C programming examples with output:
Prime or Not Prime
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf("Enter any number : ");
scanf("%d",&a);
b=1;
c=0;
while(b<=a)
{
if(a%b==0)
c=c+1;
b++;
}
if(c==2)
printf("%d is a prime number",a);
else
printf("%d is not a prime number",a);
getch();
}
Output:
Enter any number: 2
2 is a prime number
Enter any number:4
4 is not a prime number
Check others programming by click here:
0 komentar:
Post a Comment