#include <stdio.h>#include <math.h>bool PrimeNumber(int n);void main(){ int a; printf("%s","please input one integer:"); scanf("%d",&a); if(PrimeNumber(a)) printf("%d%s\n",a," is a prime number."); else printf("%d%s\n",a," not prime number.");}
bool PrimeNumber(int n){ bool flag=false; int k=(int)sqrt(n),i;
for(i=2;i<=k;i++) { if(n%i==0) flag=false; else flag=true; break; } return flag;}
Now the question is When a user enter 2 or 3 to show why not prime number.Other numbers can be displayed correctly.
thanks.