ImageVerifierCode 换一换
格式:DOCX , 页数:135 ,大小:121.24KB ,
资源ID:16986526      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/16986526.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(最新C语言上机练习参考答案文档格式.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

最新C语言上机练习参考答案文档格式.docx

1、%7cn 1-3已知某个圆的半径,编写一个程序,用来计算并显示面积。要求:将定义为符号常量,并假设一个恰当的半径值。#define PI 3.14 float r=5, s; s = PI*r*r;The area of circle is: %.2fn, s);Output 78.501-4已知两个整数20和10,编写程序,自定义函数add( )将这两个数相加,自定义函数sub( )计算这两个数的差,并按照下面形式显示计算结果: 20+10=30 20-10=10int add(int a, int b) return (a+b);int sub(int a, int b) return (

2、a-b); int a=20, b=10;%d + %d = %dn, a, b, add(a, b);%d - %d = %dn, a, b, sub(a, b);20 + 10 = 3020 10 = 101-5已知变量a、b和c的值,编写程序,用来计算并显示x的值,其中请分别用以下数值运行该程序(1)a=250,b=85,c=25(2)a=300,b=70,c=80 int a=250, b=85, c=25; float x; x=1.0*a/(b-c);x = %.2fn, x);Output (1)x = 4.17Program (2) int a=300, b=70, c=80;

3、 /*试写成x=a/(b-c); 得到什么运行结果?为什么?*/Output (2)x = -30.00第2章 常量、变量及数据类型 & 第3章 运算符和表达式3-1编写程序,求华氏温度100oF对应的摄氏温度。计算公式如下: 式中:c表示摄氏温度,f表示华氏温度。(c定义为实型,f定义为整型)Program int f=100; float c; c=5.0*(f-32)/9; /*如果是c=5*(f-32)/9; 会是什么结果?Celsius degree (corresponding to %d Fahrenheit) is: %.2f.n, f, c);Celsius degree (

4、corresponding to 100 Fahrenheit) is: 37.78.3-2一个物体从100m的高空自由落下,编写程序,求它在前3s内下落的垂直距离。设重力加速度为10m/s2。要求,将重力加速度定义为符号常量,尝试将其改为9.8 m/s2,看结果有何不同?#define G 10 int t=3; float s; s=1.0/2*G*t*t; /*如果是s=1/2*G*t*t;The falling vertical distance (in %d seconds) is:, t, s);The falling vertical distance (in 3 seconds

5、) is:45.00.3-3将球的半径R定义为符号常量,计算球的表面积(4R2)和体积(4/3*R3)。#define R 5.2 float s, v; s=4*PI*R*R; v=4.0/3*PI*R*R*R;The surface area of the ball (radius is %.2f) is: %.2f, and the volume is:, R, s, v);The surface area of the ball (radius is 5.20) is: 339.62, and the volume 588.68.3-4给定x、y和z的值,编写程序,使x等于y的值,y等

6、于z的值,z等于x的值。 int x=1, y=2, z=3, t;Before swap: x=%d, y=%d, z=%d.n, x, y, z); t=x; x=y; y=z; z=t; /*变量t的作用是什么?After swap: x=1, y=2, z=3. x=2, y=3, z=1.3-5编写一个程序,给定一个浮点数(例如456.78),显示该数的十位数字与个位数字之和(例如5+6=11)。 float f=456.78; int n, a, b; n=f; a = n%10; /*赋值后,a是什么值? b = n/10%10; /*赋值后,b是什么值?The sum of t

7、he tens digit and units digit of %.2f is: %d + %d = %d.n, f, b, a, a+b); b = n%100/10; /*该语句与上面程序不同,看看有何区别?The sum of the tens digit and units digit of 456.78 is: 5+ 6 = 11.3-6某种物品每年折旧费的计算方法如下: 编写一个程序,当给定某物品的购买价格、使用年限和每年的折旧费时,计算出其废品价值。 float price=120.65, year=3, depreciation=10.2, value; value = pr

8、ice - year*depreciation;The scrap value is %.2f.n, value);The scrap value is 90.05.3-7在库存管理中,某单个物品的经济定购数EOQ由下面等式给定: 而最优的定购时间间隔TBO由下面等式给定:编写程序,给定需求率(单位时间内的物品数)、生产成本(每个定购)和储备成本(单位时间内每种物品),计算EOQ和TBO。math.h int demand=1000; float product_cost=3.5, storage_cost=0.63, eoq, tbo; eoq=sqrt(2*demand*product_c

9、ost/storage_cost); tbo=sqrt(2*product_cost/demand/storage_cost);EOQ is %.2f, and TBO is %.2f.n, eoq, tbo);EOQ is 105.41, and TBO is 0.11.第4章 输入输出操作管理4-1输入两个数,将它们交换后输出。 int x, y, t;Please input 2 numbers: scanf(%d%d, &x, &y);Before swap, the 2 numbers are: %d, %dn, x, y); y=t;After swap, the 2 number

10、s are: 3 5 /* Blue is input */ 3, 5 5, 34-2输入一个十进制数,输出对应的八进制数和十六进制数。 int n;Please input a decimal number:%d n);The octal is %o, and the hexadecimal is %x.n, n, n); 10 /* Blue is input */The octal is 12, and the hexadecimal is a.考虑:如何得到下面的输出?The octal is 012, and the hexadecimal is 0xa.4-3编写程序,输入3个整数

11、,计算并输出它们的平均值。 int a, b, c;Please input 3 integers:%d%d%da, &b, &c);The average is %.2f.n, (a+b+c)/3.0); 4 7 -19 /* Blue is input */The average is -2.67.4-4编写一个程序,读取x和y的值,显示下面表达式的值:(1)(2)(3) float x, y;Please input x and y:%f%f(1) (x+y)/(x-y) = %.2fn, (x+y)/(x-y);(2) (x+y)/2 = %.2fn, (x+y)/2);(3) (x+

12、y)(x-y) = %.2fn, (x+y)*(x-y); 3.5 4.1 /* Blue is input */(1) (x+y)/(x-y) = -12.67(2) (x+y)/2 = 3.80(3) (x+y)(x-y) = -4.564-5计算银行存款的本息。编写程序,输入存款金额money、存期year和年利率rate,根据下列公式计算存款到期时的本息合计sum(税前),输出时保留两位小数。 float money, rate, sum; int year; Please input the deposit money:%fmoney);Please input the deposi

13、t period:%dyear);Please input the annual interest rate:rate); sum=money*pow(1+rate, year);The total principal and interest is:, sum); 2500 /* Blue is input */ 3 /* Blue is input */ 0.023 /* Blue is input */ 2676.504-6输入圆柱的高h和半径r,求圆柱体积volume=*r2*h。#define PI 3.14 float volume, r, h;Please input the r

14、adius of the cylinder:r);Please input the height of the cylinder:h); volume=PI*r*r*h;The volume of the cylinder is:, volume); 3.5 /* Blue is input */ 12.7 /* Blue is input */ 488.514-7编写一个程序,读取一个实数f,将其四舍五入的值赋值给整型变量n,输出n的值。(尝试不用if语句完成本程序,并考虑负数是否适用) float f; int n, m;Please input a real number:f); m=f

15、*10; m=m%10/5; /*m是什么值? n=n+m; /*m有何作用?The rounded integer is: %dn, n);Program (2) 如果不明白if语句,可以在学完第5章后再看。 n=f+0.5; /*是否理解该语句? 3.6 /* Blue is input */ 4 -13.2 /* Blue is input */ -134-8编写程序,读入两个两位数字的整数,并按照如下形式输出这两个整数的乘积。 4 5 * 3 7 3 1 5 1 3 5 1 6 6 5提示:注意格式! int x, y, m, n;Please input 2 integers:%5d

16、n *%3dn-n m=y%10; n=y/10;%5dn%4dn-n%5dn, x*m, x*n, x*y);第5章 判断与分支5-1输入一个字符ch,根据不同情况进行输出:(1)ch为小写字母,输出对应的大写字母;(2)ch为大写字母,按照原样输出;(3)ch为数字,输出对应的数字;(4)ch为其他字符,输出“Other character.”。 char ch;Please input a character: ch=getchar(); if (ch=a & chZ printf(, ch); else if (ch09 printf(%dn, ch- else printf(Othe

17、r character.n A /* Blue is input */A b /* Blue is input */BOutput (3)3Output (4) /* Blue is input */Other character.5-2为鼓励居民节约用水,自来水公司采用按月用水量分段计费的办法,居民应交水费y元与月用水量x吨的函数关系式如下(设x0)。编写程序,输入用户的月用水量x吨,计算并输出该用户应支付的水费y元(保留两位小数)。Please input the water consumption:x); if(x=15) y=4*x/3; /*是否可以写成y=4/3*x;?区别在哪里? else y=2.5*x-10.5;The water price is: %.2f. n, y); 27.9 /* Blue is input */ 59.255-3输入一个年份year,判断year是否为闰年。year若为闰年,需要满足下列条件之一:(1)能被4整除,但不能被100整除(如2004年是闰年,2100年不是闰年)(2)能被400整除(如2000年是闰年) int year;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1