Wednesday, 19 August 2015

Programming in C to test that the given number is prime or not

#include<stdio.h>
#include<conio.h>
void main()
{
int n,x=2;
clrscr();
printf("\n Enter the number for testing (Prime or not) :");
scanf("%d",&n);
while (x<n)
{
if (n%x==0)
{
printf("\n The number %d is not Prime.",n);
getch();
exit(0);
}
x++;
}
printf("\n The number %d is Prime.",n);
getch();
}

No comments:

Post a Comment