intmain(){int i,j,n,flag;printf("input a positive number:");scanf("%d",&n);printf("all the primes<=%d:",n);for(i=2;i<=n;i++){
flag=0;for(j=2;j<i;j++){if(i%j==0)
flag=1;}if(!flag)printf("%d\t",i);}return0;}
输出小于输入数的所有素数
intmain(){int num,i;printf("input a positive number:");scanf("%d",&num);printf("all the primes<=%d: ",num);for(i=2;i<=num;i++)if(isPrime(i))printf("%d\t",i);return0;}
输出大于输入数的最小素数
intmain(){int num,i,flag=0;printf("input a positive number:");scanf("%d",&num);for(i=num+1;;i++){if(isPrime(i)){
flag=1;printf("Maximum prime number greater than %d is %d.\n",i);}if(flag==1)break;}return0;}
输出小于输入数的最大素数
intmain(){int num,i,flag=0;printf("input a positive number:");scanf("%d",&num);for(i=num-1;i>=2;i--){if(isPrime(i)){
flag=1;printf("Maximum prime number less than %d is %d.\n",num,i);}if(flag==1)break;}return0;}
输出一个数的最大质因数
intmain(){int num,i;int max_prime=0;printf("input a positive number:");scanf("%d",&num);for(i=2;i<=num;i++){if(num%i==0&&isPrime(i)){if(max_prime<i)
max_prime=i;}}if(max_prime)printf("The maximum prime factor of %-3d is:%3d",num,max_prime);return0;}
输出大小最接近输入数的素数
intmain(){int num,i,j;printf("input a positive number:");scanf("%d",&num);for(i=num-1,j=num+1;;i--,j++){if(isPrime(i)&&isPrime(j)){printf("%d %d\n",i,j);break;}if(isPrime(i)&&!isPrime(j)){printf("%d\n",i);break;}if(!isPrime(i)&&isPrime(j)){printf("%d\n",j);break;}}return0;}
对于每个素数,输出两个彼此最接近的素数,其和等于该偶数
intmain(){int m,half,i;int temp;printf("input a positive number:");scanf("%d",&m);
half=m/2;for(i=half;i>0;i--){
temp=half*2-i;if(isPrime(i)&&isPrime(temp)){printf("%d %d\n",i,temp);break;}}return0;}