答案-C语言考试系统题库答案

举报
资源描述
分类一I.编写一程序P l-111.C实现以下功能x(x只考虑整数i n t且必须定义为i n t、但F(x)完全可能超过i n t的表示范围)通过键盘输入(输入前给出提示P leas e i n p u t x:),然后计算并在屏幕上输出国数值。注意,图1中的括号不是而是(),编程可用素材:p ri n t f (*P leas e i n p u t x:).()r-5x+27(x 0)程序的运行效果应类似地如图1所示,图1中的3是从键盘输入的内容。#i n clu d e i n t mai n(v oi d)i n t x;d ou ble y;p ri n t f(*P leas e i n p u t x:);s can f&x);i f (x 0)(y=(d ou ble)2*x -1;)els e(i f (x =0)(y=(d ou ble)79 09;)els e(y=(d ou ble)-5*x +27;)p ri n t f (n F(%d)=%.01f n*x,y);ret u rn 0;2.P l-113已知某银行整存整取存款不同期限的年息利率分别为:3.15%期限一年,3.63%期限二年,4.02%期限三年,4.69%期限五年,5.36%期限八年。从键盘上输入存钱的本金(以元为单位,必须定义为i n t且应考虑金额很大的情况)和存款期限(只考虑1,2,3,5,8),求到期时能从银行得到的利息(以 元 为 单 位,应 考 虑 有 小 数,不 计 复 利)。编 程 可 用 素 材:p ri n t f(n P leas e i n p u t ben ji n,cu n qi:)、p ri n t f (n li x i =.yu an”o程序的运行效果应类似地如图1所示,图1中的10000,8是从键盘输入的内容。8 命令提示符 口 回Please input benjincunqi:100008lixi=4288.00 yuan囚I .Ldt t i n clu d e i n t mai n(v oi d)(i n t ben ji n,cu n qi;d ou ble li x i;d ou ble mon ey;p ri n t f(n P leas e i n p u t ben ji n,cu n qi:);s can f (%d,%d,&ben ji n,&cu n qi);mon ey=ben ji n;i f (cu n qi =1)(li x i =mon ey*cu n qi *3.15/100;)els e(i f (cu n qi =2)(li x i =mon ey*cu n qi *3.63/100;els e(i f (cu n qi =3)(li x i =mon ey*cu n qi *4.02/100;)els e(i f (cu n qi =5)li x i =mon ey*cu n qi *4.69 /100;)els ei f (cu n qi -8 )(li x i =mon ey*cu n qi *5.36/100;)p ri n t f(n li x i =%.2f yu an n*,li x i);ret u rn 0;)3.P IT 14编写一个简单计算器程序,输入格式为:d at al op d at a2o其中d at al和 d at a2是参加运算的两个数(d at al、d at a2必须定义为i n t,但二者相加可能超出i n t 能表示的范围),op 为运算符,它的取值只能是+、-、*、/、%o程序的运行效果应类似地如图1、图2、图3、图4所示,图1中的3000+2000、图2 中的3000%2000、图 3 中的3000%0 和图4 中的3000/0 是从键盘输入的内容。F命令提示符BIBBPlease input datal op data2:3000 X 0Error?chu shu weit t i n clu d e i n t mai n(v oi d )(i n t d at al,d at a2;d ou ble ji eg u o;ch ar op;p ri n t f(n P leas e i n p u t d at al op d at a2:);s can f (*%d%c%d”,&d at al,&op,&d at a2);s w i t ch (op )cas e+:ji eg u o=(d ou ble)d at alp ri n t f(n%d%c%d=%.Of n”,break;cas e :ji eg u o=(d ou ble)d at alp ri n t f C n%d%c%d=%.Of n,break;cas e *:ji eg u o=(d ou ble)d at alp ri n t f(n%d%c%d=%.Of n”,break;cas e r :i f (d at a2!=0)+d at a2;d at al,op,-d at a2;d at al,op,*d at a2;d at al,op,d at a2,d at a2,d at a2,ji eg u o);ji eg u o);ji eg u o);ji eg u o=(d ou ble)d at al/d at a2;p ri n t f(n%d%c%d=%.Of n”,d at al,op,d at a2,ji eg u o);break;)els ep ri n t f(Xn Error!ch u s h u w ei 0.n);break;)cas e%:i f (d at a2!=0)ji eg u o=d at al%d at a2;p ri n t f(n%d%c%d=%.Of n”,d at al,op,d at a2,ji eg u o);break;)els e(p ri n t f(*n Error!ch u s h u w ei 0.n);break;)d ef au lt:p ri n t f(n Error!n);)ret u rn 0;)4.输入月份,打印2003年该月有几天。当输入的月份超范围时,应显示“In v ali d mon t h i n p u t”。程序的运行效果应类似地如图1和图2所示,图1中的4和图2中的13是从键盘输入的内容。t t i n clu d e i n t mai n(v oi d )i n t mon t h;i n t d ay;p ri n t f(Xn p leas e i n p u t t h e mon t h n u mber:);s can f(%d”,&mon t h);s w i t ch (mon t h )(cas e 1:cas e 3:cas e 5:case 7:case 8:case 10:case 12:day=31;printf(n2003.%d has%d days.n,month,day);break;case 4:case 6:case 9:case 11:day=30;printf C*n2003.%d has%d days.n,month,day);break;case 2:day=28;printf(n2003%d has%d days.n,month,day);break;default:printf(Xnlnvalid month inputn);return 0;)5.已知某公司员工的保底薪水为5 00,某月所接工程的利润profit(整数)与利润提成的关系如下(计量单位:元):profit1000 没有提成;1000 v profit2000 限 10%;2000 profit5 000 提成 15%;5 000 prof it10000 提成 20%;10000 profit J10G25%O请根据输入的利润计算员工的薪水。程序的运行效果应类似地如图1所示,图1中的2000是从键盘输入的内容。ttinclude int main(void)int profit;double salary=5 00;p ri n t f(*n In p u t p rof i t:*);s can f(%d”,&p rof i t);i f (p rof i t 1000&p rof i t 2000&p rof i t 5000&p rof i t 10000)(s alary=s alary+p rof i t *0.25;)p ri n t f(s alary=%.2f n”,s alary);ret u rn 0;)6.编写一程序P 7-708.C实现以下功能输入一个三位正整数,然后逆序输出。如输入123,则输出321。程序的运行效果应类似地如图1所示,图1中的752是从键盘输入的内容。#i n clu d e#i n clu d e/*i n t mai n(v oi d)i n t n u m,i;ch ar s t r4;p ri n t f(In p u t an i n t eg er:*);s can f(%d”,&n u m);i t oa(n u m,s t r,10);p ri n t f(*T h e res u lt i s );f or(i =2;i =0;i)(p ri n t f s t ri);)p ri n t f(n);ret u rn 0;*/i n t mai n(v oi d)(i n t n u m;p ri n t f(In p u t an i n t eg er:);sc a nf&num);p ri n t f(T h e res u lt i s );d opr intfnum%1 0);n u m=n u m/10;w h i le(n u m);p ri n t f(n);ret u rn 0;)7.编写一程序P 7-713.C实现以下功能用s can f输入某年某月某日,判断这一天是这一年的第几天?以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时需考虑多加一天。注:判断年份是否为闰年的方法一一为400的倍数为闰年,如2000年;若非100的倍数,而是4的倍数,为闰年,如19 9 6年。程序的运行效果应类似地如图1所示,图1中的2000-3-1是从键盘输入的内容。#i n clu d ei n t mai n(v oi d)i n t ye,mo,d a,s u m=0,i;i n t md ay13=0,31,28,31,30,31,30,31,31,30,31,30,31;p ri n t f(P leas e i n p u t:year-mon t h-d ay n);s can f(%d-%d-%d”,&ye,&mo,&d a);f or(i =1;i 2)(s u m+;)s u m=s u m+d a;p ri n t f(*It i s t h e%d t h d ay.n*,s u m);ret u rn 0;)8.P 7-723.C输入三角形的三边长a、b、c(边长可以是小数),求三角形面积area,并输出。如果输入的三边构不成三角形,应给出“d at a error”的信息提示。注:根 据“海伦-秦九韶”公式,area=.P(p-a)(p-b)(p-c),其中 p =(a+b+c)/2O程序的运行效果应类似地如图1和图2所示,图1中的3,4,5和图2中的3,4,8是从键盘输入的内容。i n clu d e t t i n clu d e i n t mai n(v oi d )(d ou ble aa,bb,cc,p p,s s,t t;p ri n t f(*n p leas e i n p u t t ri an g e s i d es:);s can f
展开阅读全文
温馨提示:
金锄头文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
相关资源
正为您匹配相似的精品文档
相关搜索

当前位置:首页 > 商业/管理/HR > 营销创新


电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号