Thursday, 2 January 2014

A PROGRAM TO CHECK WHETHER A NUMBER IS PRIME OR NOT( Different Logic From Previous Code)

#include<stdio.h>
int main()
{
int num,i,j;
printf("Enter number to check prime:");
scanf("%d",&num);
for(i=1;i<num;i++)
{
int count=0;
for(j=1;j<i;j++)
{
if(i%j==0)
{
count++;
}
}
if(count==0||count==1)
{
printf("%d is prime number\n",i);
}
else
{
printf("%d is not prime number\n",i);
}
}
getch();
return 0;
}

No comments:

Post a Comment