资源描述:
《C语言程序设计部分习题及例题参考程序复习进程.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、__________________________________________________《C语言程序设计》部分例题及课后习题参考程序1.编程计算如下分段函数:[参考程序]#includeintmain(){floatx,y;printf("inputx:");scanf("%f",&x);if(x>=10)y=2*x+3;elseif(x>=0)y=4*x;elsey=5*x-6;printf("y=%.2f",y);}2.编程将从键盘输入的百分制成绩转换为等级分,转换
2、方法如下:90以上(大于或等于90,下同)为A,80分以上为B,70分以上为C,60分以上为D,60分以下,即低于60分为E。____________________________________________________________________________________________________[参考程序]#includeintmain(){floatscore;charrank;printf("inputascore:");scanf("%f",&sco
3、re);if(score>100
4、
5、score<0){printf("invalidscoreinput");exit(-1);}switch((int)score/10){case10:case9:rank='A';break;case8:rank='B';break;case7:rank='C';break;_______________________________________________________________________________________________
6、_____case6:rank='D';break;default:rank='E';}printf("%.2f:%c",score,rank);return0;}3.编程判断以从键盘输入的三个数为边长,是否能构成三角形。[参考程序]#includeintmain(){floata,b,c;printf("inputa,b,c:");scanf("%f%f%f",&a,&b,&c);if(a>0&&b>0&&c>0&&a+b>c&&a+c>b&&b+c>a)printf("(%.2
7、f,%.2f,%.2f)能围成三角形",a,b,c);else____________________________________________________________________________________________________printf("(%.2f,%2.2f,%.2f)不能围成三角形",a,b,c);}4.编程实现将从键盘输入的一个正整数逆序输出,如输入1234,输出3421[参考程序]#includeintmain(){intn;pr
8、intf("inputanumber:");scanf("%d",&n);do{printf("%d",n%10);n/=10;}while(n!=0);return0;}5.输入一个1~10范围内的整数,计算该数的阶乘。[参考程序]#include____________________________________________________________________________________________________intmain(){intn,s=1,i
9、;printf("inputanumber(1~10):");scanf("%d",&n);for(i=2;i<=n;i++)s*=i;printf("%d!=%d",n,s);return0;}6.从键盘输入的一行字符,统计其含有多少个字符。【参考程序】#includeintmain(){charch;intcnt=0;printf("inputacharline:");ch=getchar();while(ch!=''){cnt++;____________________
10、________________________________________________________________________________ch=getchar();}printf("%d",cnt);return0;}7.打印乘法口诀表。【参考程序】#includeintmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j<=i;j++)printf("%d*%d=%