#include <stdio.h> #include <math.h> #define YES 1 #define NO 0 void main() { int n; int Prime_num(int n);//聲明Prime_num函數 printf("please enter a number:"); scanf("%d",&n);//輸入要判斷的的數 Prime_num(n);//調用Prime_num函數 if(Prime_num(n)==YES) printf("%d is a prime number\n",n); else printf("%d is not a prime number\n",n); } int Prime_num(int n)//定義Prime_num函數 { int i; if(n==2) return YES; else if(n<2||n%2==0) return NO; else { for(i=3;i<=sqrt(n);i+=2) { if(n%i==0) return NO; } } return YES; }