1、C语言第五章编程题3.用for循环语句编程输出AZ之间的所有字符,两字母之间以空格分隔,要求一行输出8个字符。#includevoid main()char c;int count=0;for(c=A;c=Z;c+)printf(%c ,c);count+;if(count%8=0) printf(n);5.输出1至1000之间所有满足用3除余2、用5除余3、用7除余2的数(要求每行只输出5个数)。#includevoid main()int i;int count=0;for(i=1;i=1000;i+)if(i%3=2&i%5=3&i%7=2)printf(%d ,i);count+;if
2、(count%5=0) printf(n);6.先读入一个正整数n,然后计算并显示前n个偶数的和。例如n为5,则求2+4+6+8+10的值,即sum=30。#includevoid main()int i,n,sum;printf(输入一个正整数:n);scanf(%d,&n);i=1;sum=0;while(i=n)sum+=2*i;i+;printf(sum=%dn,sum);7.计算S=1+1/2+1/3+1/4+.+1/200的值并输出。#includevoid main()int i;float S=0.0;for(i=1;i=200;i+)S=S+1.0/i;printf(S=%.
3、0fn,S);8.计算1-3+5-7+-99+101的值。#includevoid main()int i,s=1;float sum=0.0;for(i=1;i=101;i=i+2)sum=sum+i*s;s=-s;printf(sum=%.2fn,sum);10. 输出Fibonacci数列的前几项,直到该项的值大于10000为止(每行输出5项)。fobinacci数列为1,1,2,3,5,8,13,21,34,。即第一项和第二项为1,其他为前两项之和。#includevoid main()int f1=1,f2=1,f3=f1+f2;int count=2;printf(%10d%10d
4、,f1,f2);while(f3=10000)printf(%10d,f3);f1=f2;f2=f3;f3=f1+f2;count+;if(count%5=0)printf(n);教材P103页11. 编写程序,输出1000099999之间的所有回文数。#includevoid main()long i;int a,b,c,d,count=0;for(i=10000;i=99999;i+)a=i%10;b=i/10%10;c=i/1000%10;d=i/10000;if(a=d&b=c)count+;printf(%ld ,i);if(count%8=0) printf(n);12. 找出10
5、0999之间的水仙花数。#includevoid main()int i,a,b,c;for(i=100;i=999;i+) a=i%10; b=i/10%10; c=i/100; if (i =(a*a*a+b*b*b+c*c*c) printf(%dn,i);13. 输出10100之间各位数字之积大于各位数字之和的数。#includevoid main()int i,a,b;for(i=10;ia+b)printf(%dn,i);14 输入一个整数,计算该整数的位数和各位数字之和。(本题很重要!)#includevoid main()int i,sum=0,num=0;printf(输入一
6、个整数:n);scanf(%d,&i);if(i0;) sum=sum+i%10; num+; i=i/10; printf(sum=%d,num=%dn,sum,num);15. 输入一个整数,判断是否完数。#includevoid main()int n,i,sum=0;printf(输入一个整数:n);scanf(%d,&n);for(i=1;i=n-1;i+) if(n%i=0) sum=sum+i; if(sum=n) printf(%d是完数!n,n);else printf(%d不是完数!n,n);16#includevoid main()int i,j;printf(tttt乘
7、法口诀表n);for(i=1;i=9;i+) for(j=1;j=i;j+) printf(%d*%d=%dt,i,j,i*j); printf(n);17. 输出图形:#includevoid main()int i,j;char c=A;for(i=1;i=4;i+) for(j=1;j=5-i;j+) printf( ); for(j=1;j=2*i-1;j+) printf(%c,c); c+; printf(n);18. 输出图形:#includevoid main()int i,j;for(i=1;i=4;i+) for(j=1;j=1;i-) for(j=1;j=2*i-1;j+
8、) printf(* ); printf(n);19. 找出10000以内的所有完数。#includevoid main()int n,i,sum=0;for(n=2;n=10000;n+) sum=0; for(i=1;i=n-1;i+) if(n%i=0) sum=sum+i; if(sum=n) printf(%dn,n);20. 找出500以内的所有素数。#includevoid main() int i,j,count=0; printf(1 ); for(i=2;i=500;i+) for(j=2;ji;j+) if(i%j=0) break; if(i=j) printf(%d
9、,i); count+; if(count%8=0) printf(n); 2126. 也要求完成,题目见教材21#includevoid main() int i; float a=2.0,b=1.0,c,sum=0.0,temp;for(i=1;i=20;i+) c=a/b; sum=sum+c; temp=a+b; b=a; a=temp; printf(sum=%fn,sum);22#includevoid main() int i,ge,shi,bai,num=0;for(i=100;i=999;i+) ge=i%10; shi=i/10%10; bai=i/100; if(ge+s
10、hi+bai=5) num+; printf(%dn,i); printf(nnum=%dn,num);23#includevoid main() int i,count=0;for(i=1500;i=3000;i+) if(i%4=0&i%100!=0)|(i%400=0) printf(%d ,i); count+; if(count%8=0) printf(n); 24#includevoid main() int i,ge,shi;for(i=10;i=99;i+) ge=i%10; shi=i/10; if(i-(ge*10+shi)=45) printf(AB=%dn,i); 25#includevoid main() int x,y,z;for(x=0;x=9;x+) for(y=0;y=12;y+) z=(36-x-y); if(4*x+3*y+z/2.0=36)&(z%2=0) printf(x=%dny=%dnz=%dn,x,y,z); 26#includevoid main() int x,y,z;for(x=0;x=17;x+) for(y=0;y=25;y+) z=(30-x-y); if(3*x+2*y+z=50) printf(x=%d y=%d z=%dnn,x,y,z);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1