Write a C program to Check whether a given number is a prime or not
Program:-
#include<stdio.h>
int main()
{
int n,i;
printf(“\nEnter the number : “);
scanf(“%d”,&n);
for(i = 2; i <= n/2; i++)
{
if(n % i ==0)
{
break;
}
}
if(i > n/2)
printf(“\n%d is a Prime Number\n”,n);
else
printf(“\n%d is not a Prime Number\n”, n);
return 0;
}
int main()
{
int n,i;
printf(“\nEnter the number : “);
scanf(“%d”,&n);
for(i = 2; i <= n/2; i++)
{
if(n % i ==0)
{
break;
}
}
if(i > n/2)
printf(“\n%d is a Prime Number\n”,n);
else
printf(“\n%d is not a Prime Number\n”, n);
return 0;
}
Output:-
....
0 comments:
Post a Comment