GIVEN NUMBER IS PRIME OR NOT - C-Tutorial

Latest

Monday, 26 September 2016

GIVEN NUMBER IS PRIME OR NOT

/* GIVEN NUMBER IS PRIME OR NOT */

#include<stdio.h>
#include<conio.h>

main()
{
int i=1,n,count=0;
clrscr();
printf("\n Enter n value:");
scanf("%d",&n);
while(i<=n)
{
if(n%i==0)
{
count=count+1;
}
i=i+1;
}
if(count==2)
{
printf("\n The given number is prime number: %d",n);
}
else
{
printf("\n The given number is not a prime number: %d",n);
}
getch();
}

No comments:

Post a Comment