#include<stdio.h> #include<conio.h> int main() { int num,i,isPrime=0; clrscr(); printf("please enter the number you check prime \n"); scanf("%d",&num); if(num <= 1) printf("the number %d is not prime",num); else if(num == 1) printf("the number %d is not prime",num); else if(num == 2) printf("the number %d is prime",num); else{ for(i=3;i*i<= num ;i++) { if(num % i == 0) { isPrime= 0; break; } } if( isPrime == 0) printf("the number %d is prime",num); else printf("the number %d is not prime",num); } getch(); return 0; }
isPrime
Quote:int num,i,isPrime=0;
int num,i,isPrime=1;
Quote:for(i=3;i*i<= num ;i++)
for(i=2;i*i<= num ;i++)
Quote:if( isPrime == 0)
if( isPrime == 1)
if(num <= 1)
if(num < 1)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)