Answer to Question #46367 in C for mater

Question #46367
Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd integer is prime if it is not divisible by any odd integer less than or equal to the square root of the number.)
1
Expert's answer
2014-09-24T12:35:41-0400
#include <stdlib.h>
#include<stdio.h>
//function to check Is Prime or not
bool IsPrime(int number) {
for (int i = 3; i < number; i++) {
if (number % i == 0) return false;
}
return true;
}
//main method
int main() {

//promt user to enter number
printf("Enter number: ");
int number;
//read number
scanf("%d",&number);
// display it on screen
if(IsPrime(number)==true){
printf("Is prime number\n");
}else{
printf("Is NOT prime number\n");
}

//delay
system("pause");
//return 0
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!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS