C语言全部题目及答案.docx
- 文档编号:2034261
- 上传时间:2022-10-26
- 格式:DOCX
- 页数:23
- 大小:23.31KB
C语言全部题目及答案.docx
《C语言全部题目及答案.docx》由会员分享,可在线阅读,更多相关《C语言全部题目及答案.docx(23页珍藏版)》请在冰豆网上搜索。
C语言全部题目及答案
C语言全部题目及答案
Exercise1:
ProgrammingEnvironmentandBasicInput/Output
1.Writeaprogramthatprints“Thisismyfirstprogram!
”onthescreen、
(a)Savethisprogramontoyourowndiskwiththenameofe2-1a;
(b)RunthisprogramwithoutopeningTurboC;
(c)Modifythisprogramtoprint“Thisismysecondprogram!
”,thensaveitase2-1b、Pleasedonotoverwritethefirstprogram、
2.Writeaprogramthatprintsthenumber1to4onthesameline、Writetheprogramusingthefollowingmethods:
(a)Usingfour“printf”statements、
(b)Usingone“printf”statementwithnoconversionspecifier(i、e、no‘%’)、
(c)Usingone“printf”statementwithfourconversionspecifiers
3.(a)Writeaprogramthatcalculatesanddisplaysthenumberofminutesin15days、
(b)Writeaprogramthatcalculatesanddisplayshowmanyhours180minutesequalto、
(c)(Optional)Howabout174minutes?
ANSWERS:
#include
intmain()
{
printf("Thisismyfirstprogram!
");
return0;
}
#include
intmain()
{
printf("Thisismysecondprogram!
");
return0;
}
#include
intmain()
{
printf("1");
printf("2");
printf("3");
printf("4");
return0;
}
#include
intmain()
{
printf("1234");
return0;
}
#include
intmain()
{
printf("%d%d%d%d",1,2,3,4);
return0;
}
#include
intmain()
{
floatdays,minutes;
days=15;
minutes=days*24*60;
printf("Thenumberofminutesin15daysare%f\n",minutes);
return0;
}
#include
intmain()
{
floatminutes,hours;
minutes=180;
hours=minutes/60;
printf("180minutesequalto%fhours\n",hours);
return0;
}
#include
intmain()
{
floatminutes,hours;
minutes=174;
hours=minutes/60;
printf("174minutesequalto%fhours\n",hours);
return0;
}
Exercise2:
DataTypesandArithmeticOperations
1、Youpurchasealaptopcomputerfor$889、Thesalestaxrateis6percent、WriteandexecuteaCprogramthatcalculatesanddisplaysthetotalpurchaseprice(netprice+salestax)、
2.Writeaprogramthatreadsintheradiusofacircleandprintsthecircle’sdiameter,circumferenceandarea、Usethevalue3、14159for“π”、
3.Writeaprogramthatreadsintwonumbers:
anaccountbalanceandanannualinterestrateexpressedasapercentage、Yourprogramshouldthendisplaythenewbalanceafterayear、Therearenodepositsorwithdraws–justtheinterestpayment、Yourprogramshouldbeabletoreproducethefollowingsamplerun:
Interestcalculationprogram、
Startingbalance?
6000
Annualinterestratepercentage?
4、25
Balanceafteroneyear:
6255
ANSWER:
#include
intmain()
{
floatnet_price,sales_tax,total;
net_price=889;
sales_tax=net_price*0、06;
total=net_price+sales_tax;
printf("Thetotalpurchasepriceis%g",total);
return0;
}
#include
intmain()
{
printf("Pleaseinputanumberasradius:
\n");
floatradius,diameter,circumference,area;
scanf("%f",&radius);
printf("Thediameteris%g\n",diameter=radius*2);
printf("Thecircumferenceis%g\n",circumference=radius*2*3、14159);
printf("Theareais%g\n",area=radius*radius*3、14159);
return0;
}
#include
intmain()
{
floatSB,percentage,NB;
printf("Interestcalculationprogram\n\nPleaseentertheStartingBalance:
");
scanf("%f",&SB);
printf("PleaseentertheAnnualinterestratepercentage:
");
scanf("%f",&percentage);
NB=SB*percentage/100+SB;
printf("\nTheBalanceafteroneyearis:
%g",NB);
return0;
}
Exercise3:
Selectionstructure
1.WriteaCprogramthatacceptsastudent’snumericalgrade,convertsthenumericalgradetoPassed(gradeisbetween60-100),Failed(gradeisbetween0-59),orError(gradeislessthan0orgreaterthan100)、
2.Writeaprogramthataskstheusertoenteranintegernumber,thentellstheuserwhetheritisanoddorevennumber、
3.Writeaprogramthatreadsinthreeintegersandthendeterminesandprintsthelargestinthegroup、
ANSWER:
#include
intmain()
{
intgrade;
printf("Pleaseenterthegrade:
");
scanf("%d",&grade);
if(grade>=60&&grade<=100)
printf("Passed、");
elseif(grade>=0&&grade<60)
printf("Failed、");
else
printf("Error、");
return0;
}
#include
intmain()
{
inta,b,c;
printf("Pleaseenter3integernumbers\n");
printf("ThenI'lltellyouwhichisthelargest\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
printf("%disthelargest",a);
elseif(b>a&&b>c)
printf("%disthelargest",b);
elseif(c>a&&c>b)
printf("%disthelargest",c);
else
printf("They'reequal");
return0;
}
#include
#include
intmain()
{
inta;
printf("Pleaseenteranintegernumber\n");
printf("ThenI'lltellyouwhetherit'sanoddorevennumber");
scanf("%d",&a);
if(a%2==0)
printf("%disanevennumber",a);
else
printf("%disaod
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 全部 题目 答案
![提示](https://static.bdocx.com/images/bang_tan.gif)