成都信息工程学院C语言作业答案_第1页
成都信息工程学院C语言作业答案_第2页
成都信息工程学院C语言作业答案_第3页
成都信息工程学院C语言作业答案_第4页
成都信息工程学院C语言作业答案_第5页
已阅读5页,还剩89页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

分类一1. 编写一程序 P1-111.C 实现以下功能x(x 只考虑整数 int 且必须定义为 int、但 F(x)完全可能超过 int 的表示范围)通过键盘输入(输入前给出提示 Please input x:),然后计算并在屏幕上输出函数值。注意,图 1 中的括号不是 0)y = (double) 2 * x - 1;elseif (x = 0)y = (double) 7909;elsey = (double) - 5 * x + 27;printf(“nF(%d) = %.0lfn“, x, y);return 0;2. P1-113 已知某银行整存整取存款不同期限的年息利率分别为:3.15%期限一年,3.63%期限二年, 4.02%期限三年,4.69%期限五年,5.36%期限八年。从键盘上输入存钱的本金(以元为单位,必须定义为 int 且应考虑金额很大的情况)和存款期限(只考虑 1,2,3,5,8),求到期时能从银行得到的利息(以元为单位,应考虑有小数,不计复利)。编程可用素材:printf(“nPlease input benjin,cunqi:“).、printf(“nlixi = . yuan“.。程序的运行效果应类似地如图 1 所示,图 1 中的 10000,8 是从键盘输入的内容。#include int main(void)int benjin, cunqi;double lixi;double money;printf(“nPlease input benjin,cunqi:“);scanf(“%d,%d“, money = benjin;if ( cunqi = 1 )lixi = money * cunqi * 3.15 / 100;elseif ( cunqi = 2 )lixi = money * cunqi * 3.63 / 100;else if ( cunqi = 3 )lixi = money * cunqi * 4.02 / 100;elseif ( cunqi = 5 )lixi = money * cunqi * 4.69 / 100;else if ( cunqi = 8 )lixi = money * cunqi *5.36 / 100;printf(“nlixi = %.2f yuann“, lixi);return 0;3. P1-114 编写一个简单计算器程序,输入格式为:data1 op data2。其中 data1 和 data2 是参加运算的两个数(data1、data2 必须定义为 int,但二者相加可能超出 int 能表示的范围),op 为运算符,它的取值只能是+、-、*、/、%。程序的运行效果应类似地如图 1、图 2、图 3、图 4 所示,图 1 中的 3000 + 2000、图 2 中的3000 % 2000、图 3 中的 3000 % 0 和图 4 中的 3000 / 0 是从键盘输入的内容。#include int main( void )int data1, data2;double jieguo;char op;printf(“nPlease input data1 op data2:“);scanf(“%d %c %d“, switch ( op )case +:jieguo = ( double ) data1 + data2;printf(“n%d%c%d=%.0fn“, data1, op, data2, jieguo);break;case -:jieguo = ( double ) data1 - data2;printf(“n%d%c%d=%.0fn“, data1, op, data2, jieguo);break;case *:jieguo = ( double ) data1 * data2;printf(“n%d%c%d=%.0fn“, data1, op, data2, jieguo);break;case /:if ( data2 != 0 )jieguo = ( double ) data1 / data2;printf(“n%d%c%d=%.0fn“, data1, op, data2, jieguo);break;elseprintf(“nError! chu shu wei 0.n“);break;case %:if ( data2 != 0 )jieguo = data1 % data2;printf(“n%d%c%d=%.0fn“, data1, op, data2, jieguo);break;elseprintf(“nError! chu shu wei 0.n“);break;default:printf(“nError!n“);return 0;4.输入月份,打印 2003 年该月有几天。当输入的月份超范围时,应显示“Invalid month input” 。程序的运行效果应类似地如图 1 和图 2 所示,图 1 中的 4 和图 2 中的 13 是从键盘输入的内容。#include int main( void )int month;int day;printf(“nplease input the month number:“);scanf(“%d“, switch ( month )case 1:case 3:case 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(“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(“nInvalid month inputn“);return 0; 5.已知某公司员工的保底薪水为 500,某月所接工程的利润 profit(整数)与利润提成的关系如下(计量单位:元):profit1000 没有提成;1000profit2000 提成 10%;2000profit5000 提成 15%;5000profit10000 提成 20%;10000profit 提成 25%。请根据输入的利润计算员工的薪水。程序的运行效果应类似地如图 1 所示,图 1 中的 2000 是从键盘输入的内容。#include int main( void )int profit;double salary = 500;printf(“nInput profit:“);scanf(“%d“, if ( profit 1000 printf(“salary=%.2fn“, salary); return 0;6.编写一程序 P7-708.C 实现以下功能输入一个三位正整数,然后逆序输出。如输入 123,则输出 321。程序的运行效果应类似地如图 1 所示,图 1 中的 752 是从键盘输入的内容。#include#include/*int main(void)int num, i;char str4;printf(“Input an integer:“);scanf(“%d“, itoa(num, str, 10);printf(“The result is “);for(i = 2; i = 0; i-)printf(“%c“, stri);printf(“n“);return 0;*/int main(void)int num;printf(“Input an integer:“);scanf(“%d“, printf(“The result is “);doprintf(“%d“, num%10);num = num/10; while (num);printf(“n“);return 0;cf7. 编写一程序 P7-713.C 实现以下功能用 scanf 输入某年某月某日,判断这一天是这一年的第几天?以 3 月 5 日为例,应该先把前两个月的加起来,然后再加上 5 天即本年的第几天,特殊情况,闰年且输入月份大于 3 时需考虑多加一天。注:判断年份是否为闰年的方法为 400 的倍数为闰年,如 2000 年;若非 100 的倍数,而是 4 的倍数,为闰年,如 1996 年。程序的运行效果应类似地如图 1 所示,图 1 中的 2000-3-1 是从键盘输入的内容。#includeint main(void)int ye, mo, da, sum = 0, i;int mday13 = 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31; printf(“Please input: year-month-dayn“);scanf(“%d-%d-%d“, for (i = 1; i 2)sum+;sum = sum + da;printf(“It is the %dth day.n“, sum);return 0;8. P7-723.C 输入三角形的三边长 a、b、c(边长可以是小数),求三角形面积 area,并输出。如果输入的三边构不成三角形,应给出“data error”的信息提示。注:根据“海伦秦九韶”公式,areap(p-a)(p-b)(p-c),其中 p(a+b+c)/2。程序的运行效果应类似地如图 1 和图 2 所示,图 1 中的 3,4,5 和图 2 中的 3,4,8 是从键盘输入的内容。#include #include int main( void )double aa, bb, cc, pp, ss, tt;printf(“nplease input triange sides:“);scanf(“%lf,%lf,%lf“, if ( ( aa + bb cc ) tt = pp * ( pp - aa ) * ( pp - bb ) * ( pp - cc );ss = sqrt( tt );printf(“narea=%.2lfn“, ss);elseprintf(“ndata errorn“);return 0; 9. 7-731 输出 n 行星号,每行 5 个*星号。程序的运行效果应类似地如图 1 所示,图 1 中的 4 是从键盘输入的内容。#include int main( void )int nn, i;printf(“nplease input n:“);scanf(“%d“, for ( i = 1;

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论