较为基础
代码如下
1 #include <stdio.h> 2 int fun(int n) 3 { 4 int i; 5 for(i=2;i<n;i++) 6 if(n%i==0) 7 return 0; 8 return 1; 9 } 10 int main() 11 { 12 int count=0; 13 FILE *fp=fopen("prime.txt","w+"); 14 if(fp==0) 15 { 16 printf("erroe"); 17 } 18 for(int i=2;i<300;i++) 19 { 20 if(fun(i)&&fun(i+2)) 21 { 22 count++; 23 printf("两个素数为%d %d\n",i,i+2); 24 printf("总共有%d对",count); 25 fprintf(fp,"两个素数为%d %d\n",i,i+2); 26 } 27 } 28 return 0; 29 }
标签:双胞胎,int,问题,素数,fun,include From: https://www.cnblogs.com/mayang150/p/doublesushu.html