C语言第5章 循环结构.ppt

学习纪律 上课迟到(以铃声落音为准,站着听课20分钟,特殊原因除外) 上课旷课(达6节,平时成绩0分) 作业(或报告)抄袭、雷同(该次作业成绩记0分,达3次以上,平时成绩0分) 作业缺交(若未补交,缺3次以上,平时成绩0分) 1.下面程序的功能是计算n!。 #include stdio.h main( ) { int i, n; long p; printf ( Please input a number:\n ); scanf (%d, n); p=_____________; for (i=2; i=n; i++) ________________; printf(n!=%ld, p); } 1 p=p*i;或p*=i; 习题三 ● 程序填空题   2.下面程序的功能是:从键盘上输入若干学生的成绩,统计并输出最高和最低成绩,当输入负数时结束输入。 #include stdio.h main ( ) { float score, max, min; printf ( Please input one score:\n ); scanf (%d, score); max=min=score; while ( _____________ ) { if (scoremax) max=score; if ( ______________ ) min=score; printf ( Please input another score:\n ); scanf (%d, score); } printf(\nThe max score is %f\nThe min score is %f,max,min); } score=0 scoremin 习题三 ● 程序填空题   3.下面程序的功能是:计算y= 的值。要求从键盘上输入x的值,精度控制在0.00001内。 #include stdio.h #include math.h main ( ) { float x , y=0, fz=-1, fm=-1, temp=1; printf ( Please input the value of x:\n ); scanf (%f, x); while ( _________________________ ) { fz= ___________ ; fm=fm+2; temp=fz/fm; y+=temp; } printf(\ny= %f, y); } fabs(temp)0.00001 -fz*x 习题三 ● 程序填空题   4.下面的程序完成两个数的四则运算。用户输入一个实现两个数的四则运算的表达式,程序采用switch语句对其运算进行判定后执行相应的运算并给出结果。 #include stdio.h main( ) { float x,y; char op; printf(Please input Expression:); scanf(%f%c%f,x,op,y); ___________ { case +: printf(%f%c%f=%f\n, _______________ ); ___________; switch(op) x,op,y,x+y break 习题三 ● 程序填空题   case -: printf(%f%c%f=%f\n,x,op,y,x-y); break; case *: printf(%f%c%f=%f\n,x,op,y,x*y); break; case /: if(_________________________________) printf(Division Error!\n); else printf(%f%c%f=%f\n,x,op,

文档评论(0)

1亿VIP精品文档

相关文档