66 909
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #1497 in C++ for idaira

Question #1497
Write a program that let the user to enter any positive number and the program will tell the user if the number is a prime number or not a prime number. Allow the user to continue the process until the user enters a sentinel. For this program, you are required to use an alphabet as the sentinel. Use do-while loop for this program.
Expert's answer
#include <stdbool.h>
#include <stdio.h>

using namespace std;

bool is_simple(int count){
for(int i =2; i < count; i++){
if(count % i == 0)
return false;
}
return true;
}

int main(int argc, char * argv[]){

char * str;

do{
int count;

str = new char[30];
cin >> str;

count = atoi(str);

if(is_simple(count)){
printf("Is simple.
");
}else{
printf("Is not simple!
");
}

}while(!isalpha((int)(*str)));


return 0;
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions