Answer to Question #236637 in C++ for Emmanuel Kwarfo

Question #236637
A) Write a program to confirm if a given number is a prime number or not.

B) Illustrate the above with a flowchart.
1
Expert's answer
2021-09-13T12:49:35-0400

A)

#include <iostream>
using namespace std;
int main() {
cout<<"Enter a number \n";
 int n, x, f = 0;
 cin>>n;
   for(x=2; x<=n/2; x++) {
      if(n%x==0) {
         f=1;
         break;
      }
   }
   if (f==0){
   	cout<<n<<" is a prime number";
   }
   
   else{
   	cout<<n<<" is not a prime number";
   }
   
   return 0;


B)




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS