Write a program to print whether a
given number is prime or composite
number .
Solutions:
#include<stdio.h>
int main()
{
int a;
printf("Enter a number to check \n");
scanf("%d",&a);
int b;
int c=0;
for(b=1;b<=a;b++)
{
if(a%b==0)
{
c=c+1;
}
}
if(c==2)
{
printf("It is prime number");
}
else
{
printf("It is composite number");
}
return 0;
}
0 Comments