99 022
Assignments Done
99%
Successfully Done
In May 2021

# 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
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;
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!

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS