求质数和 #include<stdio.h> bool prime(int k) { if(k==1) { return false; } for(int i=2;i<k;i++) { if(k%i==0) { return false; } } return true; } void main() { int n; int cnt=0,count=0; printf("请输入一个上界:"); scanf("%d",&n); for(int k=1;k<=n;k++) { if(prime(k)) { printf("%d/n",k); cnt++; } } printf("1到%d之间一共有%d个质数/n",n,cnt); for(k=2;k<=n;k++) { if(prime(k)==false) { printf("%d/n",k); count++; } } printf("1到%d之间一共有%d个合数/n",n,count-1); } 算年份 #include<stdio.h> void main() { int year; int flag=0; printf("请输入年份:"); scanf("%d",&year); if (year%4==0) { if(year%100 !=0 || year %400==0) { flag=1; } } switch (flag) { case 0: printf("您输入的年份是:%d/n",year); printf("%d年一月有31天/n",year); printf("%d年二月有28天/n",year); printf("%d年三月有31天/n",year); printf("%d年四月有30天/n",year); printf("%d年五月有31天/n",year); printf("%d年六月有30天/n",year); printf("%d年七月有31天/n",year); printf("%d年八月有31天/n",year); printf("%d年九月有30天/n",year); printf("%d年十月有31天/n",year); printf("%d年十一月有30天/n",year); printf("%d年十二月有31天/n",year); break; case 1: printf("您输入的年份是:%d/n",year); printf("%d年一月有31天/n",year); printf("%d年二月有29天/n",year); printf("%d年三月有31天/n",year); printf("%d年四月有30天/n",year); printf("%d年五月有31天/n",year); printf("%d年六月有30天/n",year); printf("%d年七月有31天/n",year); printf("%d年八月有31天/n",year); printf("%d年九月有30天/n",year); printf("%d年十月有31天/n",year); printf("%d年十一月有30天/n",year); printf("%d年十二月有31天/n",year); break; } } 统计各个类型数据的个数 #include<stdio.h> int max(int m,int n) { int temp; while(n!=0) { temp=m/n; m=n; n=temp; } return m; } void main() { int english=0,empty=0,num=0,other=0; char c; printf("请输入一行字符:"); while((c=getchar())!=10) { if(c>='A' && c<='Z' || c>='a' && c<='z') { english++; } else if(c==32) { empty++; } else if(c>='0' && c<='9') { num++; } else { other++; } } printf("您输入的英文字母有%d个/n您输入的空格有%d个/n您输入的数字有%d个/n您输入的其他字符有%d个/n",english,empty,num,other); }