1、第四章 循环程序设计参考答案一、选择题(把正确选项的字母标号填到表格中)题号1234567891011121314151617181920答案CBBBACBDBCDDCCBADBDB- 3 -二、判断题(错的填,对的填)题号1234567891011121314151617181920答案三、应用题1.把实现以下功能的for语句写在表格中。题号for语句(1)int i;for(i=6;i=66;i+=2) printf(“%d,”,i); printf(“b n”);(2)int i;for(i=7;i=67;i+=2) printf(“%d,”,i); printf(“b n”);(3)i
2、nt i,s;for(i=1,s=0;i=15;i+) s += i;printf(“%dn”,s); (4)int i,s;for(i=15,s=0;i=45;i+) if(i%2=0) s += i;printf(“%dn”,s); (5)int i,n,s;for(i=n=1,s=0;n=50;i+=3,n+) s += i;printf(“%dn”,s);2.把以下程序的执行结果写在表格中(注意结果的格式)。题号执行结果(1)#(2)#*#*#*(3)a=8,b=223.改写程序题(1)把while语句转换成for和do-while语句。(2)把for语句转换为while和do-whi
3、le语句。for(x = 1 ; x 100 ; x +) printf ( %n , x );(3)把do-while语句转换为while和for语句。x = 0; do printf ( %n , x ) ; x+ ; while (x 100);题号改写后的语句(1)fordo-whilescanf ( % , &x );for(; x ! = 9999; )printf ( %n , x );scanf ( % , &x );scanf ( % , &x );do printf ( %n , x );scanf ( % , &x ); while( x ! = 9999);(2)whi
4、ledo-whilex = 1;while(x 100)printf ( %n , x ); x +;x = 1;doprintf ( %n , x ); x +; while(x 100);(3)forwhilefor(x = 0 ; x 100 ; x +) printf ( %n , x );x = 0;while(x 100)printf ( %n , x ); x +;四、编程题1.#include stdio.hint main(void)double a,b,c,result;int i;a = 2, b = 1, result = 0;for(i=1;i=50;i+)resul
5、t += a / b;c = a + b,b = a, a = c;printf(Result=%.10fn,result);return 0;2. #include stdio.h#include math.hint main(void)int i = 2;int j;int k = 1;double x;double cosx = 1;double fac;printf(Enter x(radian): );scanf(%lf,&x);dofac = 1;for(j=1;j=0.000000001);printf(cos(%.3f)=%.5fn, x, cosx);return 0; 3.#include stdio.hint main(void)int i;for(i=1012;i9912;i+=100)if(i-7)%7=0&(i-8)%8=0&(i-9)%9=0)printf(%dn,i);return 0;