WAP to check whether number is prime or not.
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,a=0;
printf(" enter the number : "); //For printing
//Declaring Variable.printf(" enter the number : ");
scanf("%d",&n); //For Input.
for(i=2; i<n/2; i++) //For Loop.
{
if(n%i==0)
{
a=1;
break;
}
break;
}
}
if(a==0)
printf("%d is a prime number.",n); //For printing
else
printf("%d is not a prime number.",n); //For printing
getch(); //Getting a chracter or waiting for key press.
return 0;
No comments:
Post a Comment