Program
#include <stdio.h>
int main()
{
int num,i;
printf("\nEnter the number: ");
scanf("%d",&num);
if (num == 1) printf("\nNumber 1 is neither primie nor composite.\n");
void exit();
for(i=1;i<=num/2;i++)
{
if (num%i == 0 && i != 1 && num != 2 && num != 3)
{
printf("\n%d is not a prime number.\n",num);
break;
}
else
{
if (i == num/2) printf("\n%d is a prime number.\n",num);
continue;
}
}
return 0;
}
Compilation, Run and Output
[sreedhar@manchu2 cprograms]$ gcc prime.c -o prime
[sreedhar@manchu2 cprograms]$ ./prime
Enter the number: 24
24 is not a prime number.
[sreedhar@manchu2 cprograms]$ ./prime
Enter the number: 23
23 is a prime number.
[sreedhar@manchu2 cprograms]$ ./prime
Enter the number: 2
2 is a prime number.
[sreedhar@manchu2 cprograms]$ ./prime
Enter the number: 1
Number 1 is neither primie nor composite.
[sreedhar@manchu2 cprograms]$
No comments:
Post a Comment