电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

C语言程序设计习题与上机实验(实验答案)

C语言程序设计习题与上机实验(实验答案)_第1页
1/13
C语言程序设计习题与上机实验(实验答案)_第2页
2/13
C语言程序设计习题与上机实验(实验答案)_第3页
3/13
第三部分 上机实验与指导(答案) 实验三 选择结构程序设计 1、 main() { float score; char grade; printf(“Please input a student’ score:”); scanf(“%f”, &score); while(score>100 || score<0) { printf(“\nInput error, try again!”); 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(“score is %5.1f, score grade is %c.\n”, score, grade); } 2、 #include main( ) { float x, y ; printf(“Please input x:”); scanf(“%f”, &x); if (x < 0) y = 0; else if (x < 10) y = x ; else if ( x < 20 ) y = 10; else if ( x < 40) y = 0.5 * x + 20; else { printf(“Input Error!”); exit (0); } printf (“y=%g”, y); } 3、 include void main(void) { int choice; /* 显示菜单及输入提示信息 */ printf("----------------------------------------------- \n") ; printf(" The Menu of Data Management \n") ; printf(" 1. Input Data \n") ; printf(" 2. Output Data \n") ; printf(" 3. Insert Data \n") ; printf(" 4. Delete Data \n") ; printf(" 0. Quit System \n") ; printf("----------------------------------------------- \n") ; printf(" Please enter your choice: \n") ; /* 接收从键盘输入的数;*/ scanf("%d", &choice); /* 根据输入数据显示不同信息 */ switch (choice) { case 1: printf("Input Data ") ; break; case 2: printf("Output Data ") ; break; case 3: printf("Insert Data ") ; break; case 4: printf("Delete Data ") ; break; case 0: printf("Thanks!"); break; default: printf("Input Error! ");exit(0); } } 实验四 循环结构程序设计 1、 #include main( ) { char ch; int i; for (i=0; i<10;i++); { ch = getchar(); if (ch >= ‘a’ && ch <...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

C语言程序设计习题与上机实验(实验答案)

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部