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.
1
Expert's answer
2011-03-07T09:16:19-0500
#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 the first!
LATEST TUTORIALS
APPROVED BY CLIENTS