Write a program to input a no. and check whether it is prime or not.
Code Written in Dev C++;
#include<stdio.h>
#include<conio.h>
int main()
{
int n, d=1, c=0, r;
printf("\nEnter any no.:- ");
scanf("%d",&n);
while(d<=n)
{
r = n % d;
if(r==0)
{
c = c + 1;
}
d = d + 1;
}
if(c==2)
{
printf("\n Given no. is Prime Number.");
}
else
{
printf("\n Given no. is not Prime Number.");
}
return 0;
}
Code Written in Turbo C++ :-
#include<stdio.h>
#include<conio.h>
void main()
{
int n, d=1, c=0, r;
clrscr();
printf("\nEnter any no.:- ");
scanf("%d",&n);
while(d<=n)
{
r = n % d;
if(r==0)
{
c = c + 1;
}
d = d + 1;
}
if(c==2)
{
printf("\n Given no. is Prime Number.");
}
else
{
printf("\n Given no. is not Prime Number.");
}
getch();
}
0 Comments