c语言习题及标准答案-爱课程mooc

上传人:千****8 文档编号:115394421 上传时间:2019-11-13 格式:DOCX 页数:50 大小:122.59KB
返回 下载 相关 举报
c语言习题及标准答案-爱课程mooc_第1页
第1页 / 共50页
c语言习题及标准答案-爱课程mooc_第2页
第2页 / 共50页
c语言习题及标准答案-爱课程mooc_第3页
第3页 / 共50页
c语言习题及标准答案-爱课程mooc_第4页
第4页 / 共50页
c语言习题及标准答案-爱课程mooc_第5页
第5页 / 共50页
点击查看更多>>
资源描述

《c语言习题及标准答案-爱课程mooc》由会员分享,可在线阅读,更多相关《c语言习题及标准答案-爱课程mooc(50页珍藏版)》请在金锄头文库上搜索。

1、第一章1.1题目内容:使用printf()在屏幕上输出 hello world!提示:#include int main()printf(hello world!n);return 0;输入格式:无输出格式:输出提示信息:hello world!n输入样例:输出样例:hello world!#include int main()printf(hello world!n);return 0;1.2在屏幕上输出多行信息(3分)题目内容:使用printf()函数在屏幕上输出以下多行信息:hello world!hello hit!hello everyone!提示:在printf()函数中转义字符n

2、表示换行。输入格式:输出格式:输出提示信息:hello world!nhello hit!nhello everyone!n输入样例:输出样例:hello world!hello hit!hello everyone!#include int main() printf(hello world!n); printf(hello hit!n); printf(hello everyone!n); return 0;1.3计算半圆弧的周长及半圆面积(3分)题目内容:编程并输出半径r=5.3的半圆弧的周长及该半圆的面积,的取值为3.14159。要求半径r和必须利用宏常量表示。输入格式:无输出格式:半

3、圆的面积输出格式:Area=%fn半圆弧的周长输出格式:circumference=%fn输入样例:输出样例:Area=44.123632circumference=16.650427#include#define PI 3.14159#define R 5.3int main() printf(Area=%fn, R*R*PI/2); printf(circumference=%fn, 2*R*PI/2); return 0;1.4计算长方体体积(3分)题目内容:编程并输出长1.2、宽4.3、高6.4的长方体的体积。要求长方体的长、宽、高必须利用const常量表示。输入格式:无输出格式:长方

4、体的体积输出格式:volume=%.3fn输入样例:输出样例:#includeint main() const float l=1.2; const float x=4.3; const float y=6.4; printf(volume=%.3fn, l*x*y); return 0;第三章3.1计算两个数的平方和(3分)题目内容:从键盘读入两个实数,编程计算并输出它们的平方和,要求使用数学函数pow(x,y)计算平方值,输出结果保留2位小数。提示:使用数学函数需要在程序中加入编译预处理命令 #include 以下为程序的输出示例:please input x and y:1.2,3.4r

5、esult=13.00输入格式:%f,%f输出格式:输入提示信息:please input x and y:n输出格式:result=%.2fn输入样例:输出样例:#include#includeint main() printf(please input x and y:n); float x, y; scanf(%f,%f, &x, &y); printf(result=%.2fn, pow(x,2)+pow(y,2); return 0;3.2逆序数的拆分计算(3分)题目内容:从键盘输入一个4位数的整数,编程计算并输出它的逆序数(忽略整数前的正负号)。例如,输入-1234,忽略负号,由1

6、234分离出其千位1、百位2、十位3、个位4,然后计算4*1000+3*100+2*10+1 = 4321,并输出4321。再将得到的逆序数4321拆分为两个2位数的正整数43和21,计算并输出拆分后的两个数的平方和的结果。以下是程序的输出示例:Input x:-1234y=4321a=43,b=21result=2290输入格式:%d输出格式:输入提示信息:Input x:n逆序数输出格式:y=%dn逆序数拆分后的输出格式:a=%d,b=%dn平方和的输出格式:result=%dn输入样例:输出样例:#includeint main() printf(Input x:n); int x; s

7、canf(%d, &x); if(x=0) x=-x; int a, b, c, d; a=x/1000; b=x/100%10; c=x/10%10; d=x%10; printf(y=%dn, d*1000+c*100+b*10+a); printf(a=%d,b=%dn, d*10+c, b*10+a); printf(result=%dn, (b*10+a)*(b*10+a)+(d*10+c)*(d*10+c); return 0;3.3拆分英文名(3分)题目内容:从键盘输入某同学的英文名(小写输入,假设学生的英文名只包含3个字母。如: tom),编写程序在屏幕上输出该同学的英文名,且

8、首字母大写(如: Tom)。同时输出组成该英文名的所有英文字符在26个英文字母中的序号。以下为程序的输出示例:input your English name:tomTomt:20o:15m:13输入格式:%c%c%c输出格式:输入提示信息:input your English name:n首字母大写的英文姓名的输出格式:%c%c%cn姓名中每个字母在26个英文字母中的序号的输出格式:%c:%dn输入样例:输出样例:#includeint main() printf(input your English name:n); char a, b, c; scanf(%c%c%c, &a, &b, &

9、c); printf(%c%c%cn, a+A-a, b, c); printf(%c:%dn, a, a-a+1); printf(%c:%dn, b, b-a+1); printf(%c:%dn, c, c-a+1); return 0;3.4计算体指数(3分)题目内容:从键盘输入某人的身高(以厘米为单位,如174cm)和体重(以公斤为单位,如70公斤),将身高(以米为单位,如1.74m)和体重(以斤为单位,如140斤)输出在屏幕上,并按照以下公式计算并输出体指数,要求结果保留到小数点后2位。假设体重为w公斤,身高为h米,则体指数的计算公式为: 以下是程序的输出示例:input weigh

10、t, height:70,174weight=140height=1.74t=23.12输入格式:%d,%d输出格式:输入提示信息:input weight, height:n (注意:在height和逗号之间有一个空格)体重输出格式:weight=%dn身高输出格式:height=%.2fn体指数输出格式:t=%.2fn输入样例:输出样例:#includeint main() int x, y; printf(input weight, height:n); scanf(%d,%d, &x, &y); printf(weight=%dn, x*2); printf(height=%.2fn,

11、 y/100.0); printf(t=%.2fn, x/(y/100.0)*(y/100.0); return 0;第四章4.1数位拆分v2.0(4分)题目内容:从键盘上输入一个4位数的整数n,编写程序将其拆分为两个2位数的整数a和b,计算并输出拆分后的两个数的加、减、乘、除和求余运算的结果。例如n=-4321,设拆分后的两个整数为a,b,则a=-43,b=-21。除法运算结果要求精确到小数点后2位。求余和除法运算需要考虑除数为0的情况,即如果拆分后b=0,则输出提示信息the second operater is zero!程序的运行结果示例1:please input n:120012,

12、0sum=12,sub=12,multi=0the second operater is zero!程序的运行结果示例2:please input n:-2304-23,-4sum=-27,sub=-19,multi=92dev=5.75,mod=-3输入格式:%d输出格式:输入提示信息:please input n:n拆分后的两个整数的输出格式:%d,%dn加法、减法、乘法的输出格式:sum=%d,sub=%d,multi=%dn除法和求余的输出格式:dev=%.2f,mod=%dn除数为0的提示信息:the second operater is zero!n输入样例:输出样例:#include main() int m,x,y; printf(please input n:n); scanf(%d,&m); x=m/100; y=m%100; printf(%d,%dn,x,y); printf(sum=%d,sub=%d,multi=%dn,x+y,x-y,x*y); if (y!=0) printf(dev=%.2f,mod=%dn,(float)x/y,x%y); else pr

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 教学课件 > 高中课件

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