# 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.)

Expert's answer

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

}

#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 orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment