资源描述:
《《C语言》实验报告答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、计算机基础实验报告(C程序)学号班级姓名指导教师金玲玲实验题目实验答案实验内容编程题:1、输入一个整数,输出其绝对值。#includevoidmain(){intdata;printf(“inputthedata:”);scanf(“%d”,&data);if(data>=0)printf(“%d”,data);elseprintf(“%d”,-data);}2、编程题:输入一个整数,判断该数是奇数还是偶数。#includevoidmain(){intdata;pr
2、intf(“inputthedata:”);scanf(“%d”,&data);if(data%2==0)printf(“%d是偶数”,data);elseprintf(“%d是奇数”,-data);}3、编程题:输入某学生的C语言成绩,判定并输出是否及格。#includevoidmain(){doublegrade;printf(“inputthec’sgrade:”);scanf(“%lf”,&grade);if(data>=60)printf(“pass”);elseprint
3、f(“notpass”);}4.编写一个程序,要求输入一个字符并判断它是字母字符、数字字符、还是其他字符。(本例需画流程图)#includeintmain(){charch;printf("Enterancharacter:");scanf("%c",&ch);if(ch>='a'&&ch<='z'
4、
5、ch>='A'&&ch<='Z')printf("%cisanalpha",ch);elseif(ch>='0'&&ch<='9')printf("%cisanumeric",
6、ch);elseprintf("%cisothercharacter",ch);return0;}5.某单位马上要加工资,增加金额取决于工龄和现工资两个因素:对于工龄大于等于20年的,如果现工资高于2000,加200元,否则加180元;对于工龄小于20年的,如果现工资高于1500,加150元,否则加120元。工龄和现工资从键盘输入,编程求加工资后的员工工资。#includeintmain(){doublesalary;intyear;printf("输入工龄和工资:");scan
7、f("%d%lf",&year,&salary);if(year>=20)if(salary>2000)salary=salary+200;elsesalary=salary+180;elseif(salary>1500)salary=salary+150;elsesalary=salary+120;printf("afteraltered:%.2f",salary);return0;}6.水果店有苹果,一级5.50元/kg,二级4.20元/kg,三级3.00元/kg,四级2.50元/kg,输入苹果的
8、等级、数量,显示出苹果的等级、数量、应付款数。#includeintmain(){doubleprice,total,num;intlevel;printf("输入苹果等级和数量:");scanf("%d%lf",&level,&num);switch(level){case1:price=5.5;break;case2:price=4.2;break;case3:price=3.0;break;case4:price=2.5;break;}total=price*num;print
9、f("%fkg%dlevelapple:%fyuan.",num,level,total);return0;}7.在屏幕上显示一张如下所示的时间表:*****Time*****1morning2afternoon3nightPleaseenteryourchoice:操作人员根据提示进行选择,程序根据输入的时间序号显示相应的问候信息,如选择1时显示"Goodmorning",选择2时显示"Goodafternoon",选择3时显示"Goodnight",对于其他选择显示"Selectionerror!
10、",用switch语句编程实现。#includemain(){intchoice;printf("*****Time*****");printf(“1morning”);printf(“2afternoon”);printf(“3night”);printf(“pleaseenteryourchoice”);scanf("%d",&choice);switch(choice){case1:printf(“Goodmo