In this program, the input number has to be checked, whether it is prime or not. The for loop condition is first checked "for(i=2;i<(n/2);i++)" after the condition is checked the if else condition is checked. Basically, the combination of for loop and if else is used in this program . the condition of prime no. is that it should not be divisible by any other no. other than itself & 1.
Program to check Prime Number.
#include<stdio.h>
#include<conio.h>
void main()
{ int n,i,c=0;
clrscr();
printf("\nprogram to check no. is prime or not :");
printf("\n\n enter no. : ");
scanf("%d",&n);
for(i=2 ; i<(n/2) ; i++)
{ if((n%i)==0)
{ c=1;
}
}
if(c==1)
{ printf("\n\n\t no. is not prime "); }
else printf("\n\n\t no. is prime ");
getch();

No comments:
Post a Comment
Guys if you think something is wrong or should be edit than please do comment.