Monday 31 December 2018

Filled Under:

check prime number or not [c programming examples with output]

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

0 komentar:

Post a Comment