哈尔滨工业大学C语言MOOC在线测试答案.docx
《哈尔滨工业大学C语言MOOC在线测试答案.docx》由会员分享,可在线阅读,更多相关《哈尔滨工业大学C语言MOOC在线测试答案.docx(116页珍藏版)》请在冰豆网上搜索。
![哈尔滨工业大学C语言MOOC在线测试答案.docx](https://file1.bdocx.com/fileroot1/2023-4/1/0f4d8085-33bf-4ee1-9ac6-6a3f2a6d5405/0f4d8085-33bf-4ee1-9ac6-6a3f2a6d54051.gif)
哈尔滨工业大学C语言MOOC在线测试答案
哈尔滨工业大学C语言2016年MOOC在线测试答案
本答案仅供参考,请勿用于商业用途
或进行未经同意的转载
第3周
1
计算两个数的平方和(3分)
题目内容:
从键盘读入两个实数,编程计算并输出它们的平方和,要求使用数学函数pow(x,y)计算平方值,输出结果
保留2位小数。
提示:
使用数学函数需要在程序中加入编译预处理命令#include
以下为程序的运行结果示例:
pleaseinputxandy:
1.2,3.4?
result=13.00
输入格式:
"%f,%f"
输出格式:
输入提示信息:
"Pleaseinputxandy:
\n"输出格式:
"Result=%.2f\n"
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:
500ms内存限制:
32000kb
#include
intmain()
{
floatx,y,S,D;
printf("Pleaseinputxandy:
\n");
scanf("%f,%f",&x,&y);
Uterinewithinfilmhyperplasiasyndrome,ovariancyst,andtumor(commontype),pelvicinflammatorysexmassuterinewithinfilmcancerthe5casesprostatehyperplasia,prostateinflammatory,prostatecancer,testiculartumor(commontype)cryptorchidism,testiculardevelopmentnotfull,Deputytestosteroneinflammatory,testicularinflammatory,fineSACcyst,finecablevaricoseveins,semencyst,sheathfilmproductliquid,fineSACcyst,finecablereversethe5casescardiovascularsystemcongenitalheart(commontype),rheumaticvalvedisease,expansiontype,andhypertrophytypemyocardialdisease...(Four)aboutnuclearmedicalQuWanyingEditor.nuclearmedicalPeiZhuguoEditor.imagenuclearmedicalChenhaozhuEditor,practicalwithinscienceChinesemedicalwillEditor.clinicaltechnologyoperationspecificationnuclearmedicalfasciclesChinesemedicalwillEditor.clinicalclinicguidenuclearmedicalfasciclesPanZhongyunEditor,clinicalnuclearmedicalWangShizhenEditor,molecularnuclearmedicalparticipationrevisedimplementationrulespersonnelLiMinghua,chenkemin,GengDaoying,LiuShiyuan,songWang,HuBing,XuZhizhang,Zhao,SunXiaoguangamendmentdate:
2010-2-25Medicaltestsectionphysiciantrainingrulesmedicaltestsection(andsaidtestmedicalsection)istodiagnosis,andprevention,andtreatmenthumandiseaseorassessmenthealthprovidesinformationforpurpose,onfromhumanofmaterialforbiology,andmicrobiology,andImmunology,andbiochemistry,andbloodImmunology,andbloodlearn,andbiologicalphysics,andcytology,testofclinicaltwolevelsubject,itslaboratoryworkhastoclinicalprovidestestinformationAdvisory(includingtestresultsexplainedandforfurtherappropriatecheckprovidesrecommends),andparticipationclinical
S=pow(x,2);
D=pow(y,2);
printf("Result=%.2f\n",S+D);
return0;
}
2
逆序数的拆分计算(3分)
题目内容:
从键盘输入一个4位数的整数,编程计算并输出它的逆序数(忽略整数前的正负号)。
例如,输入-1234,
忽略负号,由1234分离出其千位1、百位2、十位3、个位4,然后计算4*1000+3*100+2*10+1=4321,
并输出4321。
再将得到的逆序数4321拆分为两个2位数的正整数43和21,计算并输出拆分后的两个数
的平方和的结果。
以下是程序的运行结果示例:
Inputx:
-1234?
y=4321
a=43,b=21
result=2290
输入格式:
"%d"
输出格式:
输入提示信息:
"Inputx:
\n"
逆序数输出格式:
"y=%d\n"
逆序数拆分后的输出格式:
"a=%d,b=%d\n"
平方和的输出格式:
"result=%d\n"
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:
500ms内存限制:
32000kb
#include
main()
{
intx,b0,b1,b2,b3,y,a,b,c;
printf("Inputx:
\n");
scanf("%d",&x);
x=(int)fabs(x);/*取x绝对值*/
Uterinewithinfilmhyperplasiasyndrome,ovariancyst,andtumor(commontype),pelvicinflammatorysexmassuterinewithinfilmcancerthe5casesprostatehyperplasia,prostateinflammatory,prostatecancer,testiculartumor(commontype)cryptorchidism,testiculardevelopmentnotfull,Deputytestosteroneinflammatory,testicularinflammatory,fineSACcyst,finecablevaricoseveins,semencyst,sheathfilmproductliquid,fineSACcyst,finecablereversethe5casescardiovascularsystemcongenitalheart(commontype),rheumaticvalvedisease,expansiontype,andhypertrophytypemyocardialdisease...(Four)aboutnuclearmedicalQuWanyingEditor.nuclearmedicalPeiZhuguoEditor.imagenuclearmedicalChenhaozhuEditor,practicalwithinscienceChinesemedicalwillEditor.clinicaltechnologyoperationspecificationnuclearmedicalfasciclesChinesemedicalwillEditor.clinicalclinicguidenuclearmedicalfasciclesPanZhongyunEditor,clinicalnuclearmedicalWangShizhenEditor,molecularnuclearmedicalparticipationrevisedimplementationrulespersonnelLiMinghua,chenkemin,GengDaoying,LiuShiyuan,songWang,HuBing,XuZhizhang,Zhao,SunXiaoguangamendmentdate:
2010-2-25Medicaltestsectionphysiciantrainingrulesmedicaltestsection(andsaidtestmedicalsection)istodiagnosis,andprevention,andtreatmenthumandiseaseorassessmenthealthprovidesinformationforpurpose,onfromhumanofmaterialforbiology,andmicrobiology,andImmunology,andbiochemistry,andbloodImmunology,andbloodlearn,andbiologicalphysics,andcytology,testofclinicaltwolevelsubject,itslaboratoryworkhastoclinicalprovidestestinformationAdvisory(includingtestresultsexplainedandforfurtherappropriatecheckprovidesrecommends),andparticipationclinical
b3=x/1000;/*取x千位*/
b2=(x-b3*1000)/100;/*取x百位*/
b1=(x-b3*1000-b2*100)/10;/*取x十位*/
b0=x%10;/*取x个位*/
y=b3+b2*10+b1*100+b0*1000;
printf("y=%d\n",y);
a=b0*10+b1;
b=b2*10+b3;
c=(a*a)+(b*b);
printf("a=%d,b=%d\n",a,b);
printf("result=%d\n",c);
return0;
}
3
拆分英文名(3分)
题目内容:
从键盘输入某同学的英文名(小写输入,假设学生的英文名只包含3个字母。
如:
tom),编写程序在屏幕
上输出该同学的英文名,且首字母大写(如:
Tom)。
同时输出组成该英文名的所有英文字符在26个英文
字母中的序号。
以下为程序的运行结果示例:
InputyourEnglishname:
tom?
Tom
t:
20
o:
15
m:
13
输入格式:
"%c%c%c"
输出格式:
输入提示信息:
"InputyourEnglishname:
\n"首字母大写的英文姓名的输出格式:
"%c%c%c\n"
姓名中每个字母在26个英文字母中的序号的输出格式:
"%c:
%d\n"为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:
500ms内存限制:
32000kb
Uterinewithinfilmhyperplasiasyndrome,ovariancyst,andtumor(commontype),pelvicinflammatorysexmassuterinewithinfilmcancerthe5casesprostatehyperplasia,prostateinflammatory,prostatecancer,testiculartumor(commontype)cryptorchidism,testiculardevelopmentnotfull,Deputytestosteroneinflammatory,testicularinflammatory,fineSACcyst,finecablevaricoseveins,semencyst,sheathfilmproductliquid,fineSACcyst,finecablereversethe5casescardiovascularsystemcongenitalheart(commontype),rheumaticvalvedisease,expansiontype,andhypertrophytypemyocardialdisease...(Four)aboutnuclearmedicalQuWanyingEditor.nuclearmedicalPeiZhuguoEditor.imagenuclearmedicalChenhaozhuEditor,practicalwithinscienceChinesemedicalwillEditor.clinicaltechnologyoperationspecificationnuclearmedicalfasciclesChinesemedicalwillEditor.clinicalclinicguidenuclearmedicalfasciclesPanZhongyunEditor,clinicalnuclearmedicalWangShizhenEditor,molecularnuclearmedicalparticipationrevisedimplementationrulespersonnelLiMinghua,chenkemin,GengDaoying,LiuShiyuan,songWang,HuBing,XuZhizhang,Zhao,SunXiaoguangamendmentdate:
2010-2-25Medicaltestsectionphysiciantrainingrulesmedicaltestsection(andsaidtestmedicalsection)istodiagnosis,andprevention,andtreatmenthumandiseaseorassessmenthealthprovidesinformationforpurpose,onfromhumanofmaterialforbiology,andmicrobiology,andImmunology,andbiochemistry,andbloodImmunology,andbloodlearn,andbiologicalphysics,andcytology,testofclinicaltwolevelsubject,itslaboratoryworkhastoclinicalprovidestestinformationAdvisory(includingtestresultsexplainedandforfurtherappropriatecheckprovidesrecommends),andparticipationclinical
#include
intmain()
{
charx,y,z,A;
printf("InputyourEnglishname:
\n");
scanf("%c%c%c\n",&x,&y,&z);
A=x-32;/*首字母改为大写*/
printf("%c%c%c\n",A,y,z);
printf("%c:
%d\n",x,x-96);
printf("%c:
%d\n",y,y-96);
printf("%c:
%d\n",z,z-96);
}
4
计算体指数(3分)
题目内容:
从键盘输入某人的身高(以厘米为单位,如174cm)和体重(以公斤为单位,如70公斤),将身高(以
米为单位,如1.74m)和体重(以斤为单位,如140斤)输出在屏幕上,并按照以下公式计算并输出体指
数,要求结果保留到小数点后2位。
假设体重为w公斤,身高为h米,则体指数的计算公式为:
以下是程序的运行结果示例:
Inputweight,height:
70,174?
weight=140
height=1.74
t=23.12
输入格式:
"%d,%d"
输出格式:
输入提示信息:
"Inputweight,height:
\n"(注意:
在height和逗号之间有一个空格)体重输出格式:
"weight=%d\n"
身高输出格式:
"height=%.2f\n"
Uterinewithinfilmhyperplasiasyndrome,ovariancyst,andtumor(commontype),pelvicinflammatorysexmassuterinewithinfilmcancerthe5casesprostatehyperplasia,prostateinflammatory,prostatecancer,testiculartumor(commontype)cryptorchidism,testiculardevelopmentnotfull,Deputytestosteroneinflammatory,testicularinflammatory,fineSACcyst,finecablevaricoseveins,semencyst,sheathfilmproductliquid,fineSACcyst,finecablereversethe5casescardiovascularsystemcongenitalheart(commontype),rheumaticvalvedisease,expansiontype,andhypertrophytypemyocardialdisease...(Four)aboutnuclearmedicalQuWanyingEditor.nuclearmedicalPeiZhuguoEditor.imagenuclearmedicalChenhaozhuEditor,practicalwithinscienceChinesemedicalwillEditor.clinicaltechnologyoperationspecificationnuclearmedicalfasciclesChinesemedicalwillEditor.clinicalclinicguidenuclearmedicalfasciclesPanZhongyunEditor,clinicalnuclearmedicalWangShizhenEditor,molecularnuclearmedicalparticipationrevisedimplementationrulespersonnelLiMinghua,chenkemin,GengDaoying,LiuShiyuan,songWang,HuBing,XuZhizhang,Zhao,SunXiaoguangamendmentdate:
2010-2-25Medicaltestsectionphysiciantrainingrulesmedicaltestsection(andsaidtestmedicalsection)istodiagnosis,andprevention,andtreatmenthumandiseaseorassessmenthealthprovidesinformationforpurpose,onfromhumanofmaterialforbiology,andmicrobiology,andImmunology,andbiochemistry,andbloodImmunology,andbloodlearn,andbiologicalphysics,andcytology,testofclinicaltwolevelsubject,itslaboratoryworkhastoclinicalprovidestestinformationAdvisory(includingtestresultsexplainedandforfurtherappropriatecheckprovidesrecommends),andparticipationclinical
体指数输出格式:
"t=%.2f\n"
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:
500ms内存限制:
32000kb
#include