Problem 3: Find whether given number is prime or not.
Solution:
#include<stdio.h>
int main()
{
int i,j,test,count,n;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
count=0;
scanf("%d",&n);
for(j=1;j<=n;j++)
{
if(n%j==0)
count++;
}
if(count==2)
printf("1\n");
else
printf("0\n");
}
}
No comments:
Post a Comment