(C++) CPP Programs - 10
Friday, December 14, 2007
10. Write a C program to find whether the given number is prime or not and output the given number with suitable message.
/* Prime or Not*/
#include
#include
void main()
{
int i,k,num;
clrscr();
printf("Enter the value to check whether it is prime or not\n");
scanf("%d",&num);
k=0;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
k=1;
break;
}
}
if(k==0)
printf("%d is a prime number\n\a",num);
else
printf("%d is not a prime number\n\a",num);
getch();
}
0 comments:
Post a Comment