LED PANEL

Google It, You'll Get It.

Monday, January 31, 2011

Testing For a Prime Input(Number)

#include

main()
{
int i=1;
int num;
int choice = 1;

while(choice ==1)
{
printf("please enter the value to identify\n");
scanf("%d",&num);
printf("\n");

while(i<=num)

{
int count=0;
int a=1;

while(a<=i)
{
if(i%a==0)
{ count++; }
a++;
}

if(count==2 && num == i)
{
printf("%d", i);
printf(" a prime number \n\n");
}
i++;


}
printf("----------------------------------------\n"); //
printf("retry?? if YES press 1, if NO press 0\n"); //
scanf("%d",&choice); //
printf("----------------------------------------\n"); //
i=1;
}
// return 0;
}

No comments:

Post a Comment