多组测试数据,每组输入一个正整数N(1≤N≤100)和N个正整数(≥3),用空格分隔。
Output
输出所有素数,用空格隔开;再输出这些素数和。
Sample Input
10 4 5 8 12 13 24 34 37 20 88 5 1 5 8 12 13
Sample Output
5 13 37 s=55 5 13 s=18
#include
int N,i,j,a[100],b[100],q,o=0,s=0,w,t; while(scanf(\ {
s=0; o=0;
for(i=0;i scanf(\ } for(w=0;w for(q=2;q t=a[w]%q; if(t==0) break; } if(t!=0&&a[w]!=1||a[w]==2) { b[o]=a[w]; o=o+1; } } for(j=0;j printf(\ s=s+b[j]; } printf(\ printf(\ } } 求阶乘和 Time Limit:1000MS Memory Limit:65536K Total Submit:829 Accepted:326 Description 求1!+2!+3!+4!+...+20! Input 无 Output 1至20的阶乘和 Sample Input Sample Output 1!+2!+3!+4!+...+20!=2.561327e+018 #include int i,j; double a=1,s=0; for(i=1;i<=20;i++) { a=1; for(j=1;j<=i;j++) { a=a*j*1.0; } s=s+a; } printf(\ printf(\} Problem F:求一批正整数中的偶数和 Time Limit:1000MS Memory Limit:65536K Total Submit:1405 Accepted:569 Description 输入一批正整数(以零或负数为结束标志),求其中的偶数和。 Input 多组测试数据,每组输入一批正整数(以零或负数为结束标志) Output 求其中偶数和 Sample Input 9 32 12 11 -2 Sample Output 44 #include int a[100],s,j,i; while(scanf(\ { s=0; for(i=1;i<99999999;i++) { scanf(\ if(a[i]<=0) { break; } } for(j=0;j if(a[j]%2==0) { s=s+a[j]; } } printf(\ } } 统计各种字符个数 Time Limit:1000MS Memory Limit:65536K Total Submit:3108 Accepted:961 Description 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。 Input 输入一行字符,以回车符结束 Output 分别输出字母、空格、数字和其它字符的个数 Sample Input My teacher's address is \ Sample Output charaters: 38 blanks: 8 digitals: 3 others: 6 Hint 1. 可用getchar()!='\\n'来判断输入结束 2. 英文字母:a~z 和 A~Z;空格:' ';数字:0~9 思考:如何修改程序使之能分别统计大小写字母、空格、数字和其他字符的个数。 #include int z,k,s,q,i; char a[100]; while(gets(a)!=NULL) { z=0; k=0; s=0; q=0; for(i=0;a[i]!='\\0';i++) { if(a[i]>='a'&&a[i]<='z'||a[i]>='A'&&a[i]<='Z') { z=z+1; } else if(a[i]==' ') { k=k+1; } else if(a[i]>='0'&&a[i]<='9') { s=s+1; } else { q=q+1; } } printf(\ printf(\ printf(\ printf(\ printf(\ printf(\ printf(\ printf(\ } } 求最大公约数 Time Limit:1000MS Memory Limit:65536K Total Submit:1801 Accepted:1173 Description 两个数能同时被一个数所整除,这个数就是公约数。例如,12和20的公约数有1,2,4。其中4是12和20的最大公约数。 Input