Write a C program to check whether a given number is
prime or not
What is Prime number ?
A prime number is a positive integer that is divisible only by 1 and itself.
For Example , 5 ,7,11,17...etc
Program for prime or Not
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,flag=0;
printf("\n\t To Check Prime or Not ");
printf("\n\t ** ***** ***** ** ***");
printf("\n Input");
printf("\n Enter a Positive integer : ");
scanf("%d",&num);
if(num==0||num==1)
flag=1;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
flag=1;
break;
}
}
if (flag==0)
printf("\n %d is a Prime Number ",num);
else
printf("\n %d is not a Prime Number ",num);
getch();
}
Output
No comments:
Post a Comment