Posts

Showing posts with the label Checking for prime number

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...