Write program to check whether the entered number is PRIME or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,flag=0; // declare variable i, n & flag and initialize flag with 0
clrscr();
printf("\n Enter the number : ");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("\n %d is a Prime number",n);
}
else
{
printf("\n %d ia not a Prime number",n);
}
getch();
return 0;
}
Output:
Enter the number : 4
4 is not a Prime number
Enter Number : 7
7 is a Prime number
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,flag=0; // declare variable i, n & flag and initialize flag with 0
clrscr();
printf("\n Enter the number : ");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("\n %d is a Prime number",n);
}
else
{
printf("\n %d ia not a Prime number",n);
}
getch();
return 0;
}
Output:
Enter the number : 4
4 is not a Prime number
Enter Number : 7
7 is a Prime number
No comments:
Post a Comment