Tuesday, September 6, 2016

A program to check whether a number is prime or not

#include <stdio.h>
#include<math.h>


int main()
{
int number, counter, isprime = 0;

printf("please enter the positive integer value to identified prime or composite\n");

scanf("%d",&number);

for(counter=2; counter <= sqrt(number); counter++)
{

if((number % counter)==0){

isprime=1;

}

}
if(isprime==0){

printf("%d is a prime number",number);
}else{

printf("%d is a composite number",number);
}

return 0;

}

No comments:

Post a Comment