Exercise – 4 Control Flow - II
a)Write a C Program to Find
Whether the Given Number is Prime Number
program:-
#include<stdio.h>
void main()
{
int
n,i,c=0;
printf("enter a number to check if it is a
prime");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
c=c+1;
}
}
if(c==2)
printf("%d is a prime\n",n);
else
printf("%d is not a prime\n",n);
}
No comments:
Post a Comment