资源描述:
《C语言实验程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、P113:6#includevoidmain(){floatscore;chargrade;printf("请输入学生成绩:");scanf("%f",&score);while(score>100
2、
3、score<0){printf("输入有误,请重输");scanf("%f",&score);}switch((int)(score/10)){case10:case9:grade='A';break;case8:grade='B';break;case7:grade='C';b
4、reak;case6:grade='D';break;case5:case4:case3:case2:case1:case0:grade='E';}printf("成绩是%5.1f,相应的等级是%c",score,grade);}P113:7#include#includevoidmain(){longnum;intindiv,ten,hundred,thousand,ten_thousand,place;printf("请输入一个整数(0-99999):");
5、scanf("%ld",&num);if(num>9999)place=5;elseif(num>999)place=4;elseif(num>99)place=3;elseif(num>9)place=2;elseplace=1;printf("位数:%d",place);printf("每位数字为:");ten_thousand=(int)(num/10000);thousand=(int)(num-ten_thousand*10000)/1000;hundred=(int)(num-ten
6、_thousand*10000-thousand*1000)/100;ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);switch(place){case5:printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv);
7、printf("反序数字为:");printf("%d%d%d%d%d",indiv,ten,hundred,thousand,ten_thousand);break;case4:printf("%d,%d,%d,%d",thousand,hundred,ten,indiv);printf("反序数字为:");printf("%d%d%d%d",indiv,ten,hundred,thousand);break;case3:printf("%d,%d,%d",hundred,ten,
8、indiv);printf("反序数字为:");printf("%d%d%d",indiv,ten,hundred);break;case2:printf("%d,%d",ten,indiv);printf("反序数字为:");printf("%d%d",indiv,ten);break;case1:printf("%d",indiv);printf("反序数字为:");printf("%d",indiv);break;}}P137:1#include#in
9、cludevoidmain(){intm,k,i,n=0;printf("100~200间的全部素数:");for(m=101;m<=200;m=m+2){k=sqrt(m);for(i=2;i<=k;i++)if(m%i==0)break;if(i>=k+1){printf("%d",m);n=n+1;}if(n%10==0)printf("");}printf("");}P137:3#includevoidmain(){inti,j,k,n;printf
10、("水仙花数有:");for(n=100;n<1000;n++){i=n/100;j=n/10-i*10;k=n%10;if(n==i*i*i+j*j*j+k*k*k)printf("%d",n);}printf("");}P167:3#includevoidmain(){floatscore[4][4],sum;inti,j;for(i=0;i<3;i++){printf("请输入第%d个学生的4门课成绩:",i+1);for(j=0;j<4;