实验五:逻辑结构程序设计.docVIP

  • 25
  • 0
  • 约7.69千字
  • 约 11页
  • 2017-09-07 发布于陕西
  • 举报
实验五:逻辑结构程序设计#includestdio.h main() { float score; char grade; printf(请输入学生成绩:); scanf(%f,score); while (score100 , score0) { printf(\n输入有误,请重输 ); scanf(%f,score); } switch((int)(score/10)) { case 10: case 9:grade=A;break; case 8:grade=B;break; case 7:grade=C;break; case 6:grade=D;break; case 5: case 4: case 3: case 2: case 1: case 0:grade=E; } printf(成绩是%5.1f,相应的等级是%c.\n,score,grade); } (2)给出一个不多于5位的正整数,要求: ①求出它有几位数; ②分别打印出每一位数字; ③按逆序打印出各位数字; 答: #includestdio.h #includemath.h void main() { long int num; int indiv,ten,hundred,thousand,ten_thousand,place; printf(请输入一个整数: ); scanf(%ld,num); if(num9999) place=5; else if(num999) place=4; else if(num99) place=3; else if(num9) place=2; else place=1; printf(位数=%d\n,place); printf(每位数字为:); ten_thousand=num/10000; thousand=(int)(num-ten_thousand*10000)/1000; hundred=(int)(num-ten_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) { case 5:printf(%d,%d,%d,%d,%d\n,ten_thousand,thousand,hundred,ten,indiv); printf(反序数字为:); printf(%d,%d,%d,%d,%d\n,indiv,ten,hundred,thousand,ten_thousand); break; case 4:printf(%d,%d,%d,%d\n,thousand,hundred,ten,indiv) ; printf(反序数字为:); printf(%d,%d,%d,%d\n,thousand,hundred,ten,indiv); break; case 3:printf(%d,%d,%d\n,hundred,ten,indiv); printf(反序数字为:); printf(%d,%d,%d\n,indiv,ten,hundred); break; case 2:printf(%d,%d\n,ten,indiv); printf(反序数字为:); printf(%d,%d\n,indiv,ten); break; case 1:printf(%d,indiv); break; } getch(); } (3)编写程序,从键盘接收一个简单的表示四则运算的表达式,计算结果并输出。例如,输入“20+32”,输出“20+32=52”。分别使用switch和els

文档评论(0)

1亿VIP精品文档

相关文档