Prime number program in C
Prime number program in C. The smallest prime number is 2 and in general prime number is only divisible by 1 and number itself.Prime Number Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i,no,prime=0;
clrscr();
textcolor(4);
gotoxy(20,10);
cprintf("ENTER ANY NUMBER ");
scanf("%d",&no);
if(no==1)
{
gotoxy(20,12);
printf("%d IS NOT A PRIME NUMBER ",no);
prime=1;
}
for(i=2;i<no;i++)
{
if(no%i==0)
{
gotoxy(20,12);
printf("%d IS NOT A PRIME NUMBER",no);
prime=1;
}
}
if(prime==0)
{
gotoxy(20,12);
printf("%d IS A PRIME NUMBER",no);
}
getch();
}
Output
No comments:
Post a Comment