Program for checking whether input number is Prime or not


#include<stdio.h>
#include<conio.h>
void main()
{
int n,n1,i;
printf("\nEnter any positive integer number to check");
scanf("%d",&n);
if(n==1 || n==2)
printf("\nThe number is Prime");
else
{
i=2;
while(i<=n)
{
if(n%i==0)
break;
i++;
}
if(n==i)
printf("\nThe Number is Prime");
else
printf("\nThe Number is Not Prime");
}
printf("\nPress any key to continue...");
getch();
}

 Output

Enter any positive integer number to check 4

The Number is Not Prime
Press any key to continue...
Enter any positive integer number to check
7
The Number is Prime
Press any key to continue...

Comments

Popular posts from this blog

Program for calculating Simple Interest using the concept of Default Arguments

Data communication Terminology

Program for Checking whether the given number is Palindrome or not