资源描述:
《《C语言编程练习》PPT课件》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、7/20/2021ProgrammingExercisesNorthChinaElectricPowerUniversity7/20/2021Chapter4ManagingInputandOutputOperations4.24.2Writeaprogramtoreadthevaluesofxandyandprinttheresultsofthefollowingexpressionsinoneline:(a)(b)(c)7/20/2021Chapter4ManagingInputand
2、OutputOperations4.2main(){floatx,y;printf("Pleaseinputthevalueofxandy:");printf("x=");scanf("%f",&x);printf("y=");scanf("%f",&y);printf("(a)(x+y)/(x-y)=%f",(x+y)/(x-y));printf("(b)(x+y)/2=%f",(x+y)/2);printf("(c)(x+y)(x-y)=%f",(x+y)*(x-y));}7/20
3、/2021Chapter4ManagingInputandOutputOperations4.34.3Writeaprogramtoreadthefollowingnumbers,roundthemofftothenearestintegersandprintouttheresultsinintegerform:35.750.21-23.73-46.457/20/2021Chapter4ManagingInputandOutputOperations4.3main(){floatx;printf("
4、Pleaseinputthenumber:");scanf("%f",&x);printf("Thenumberis:%.0f",x);}7/20/2021Chapter4ManagingInputandOutputOperations4.54.5Writeaninteractiveprogramtodemonstratetheprocessofmultiplication.Theprogramshouldasktheusertoentertwotwo-digitintegersandprintt
5、heproductofintegersasshownbelow.45×377×45is3153×45is135Addthem16657/20/2021Chapter4ManagingInputandOutputOperations4.5main(){intx,y,m,n;printf("Pleaseinput2two-digitintegers:");scanf("%d%d",&x,&y);printf("tt%6dtt*%5d",x,y);printf("tt______
6、");printf("%d*%distt%6d",y%10,x,y%10*x);printf("%d*%distt%5d",y/10,x,y/10*x);printf("tt______");printf("Addthemt%6d",y*x);printf("tt______");}7/20/2021Chapter5DecisionMakingandBranching5.15.1Writeaprogramtodeterminewhetheragivennumber
7、is'odd'of'even'andprintthemessageNUMBERISEVENorNUMBERISODD(a)withoutusingelseoption,and(b)withelseoption.7/20/2021Chapter5DecisionMakingandBranching5.1main()/*(a)*/{intn;printf("Pleaseinputaninteger:");scanf("%d",&n);if(n%2)printf("%dISODD",n);if(n%
8、2==0)printf("%dISEVEN",n);}7/20/2021Chapter5DecisionMakingandBranching5.1main()/*(b)*/{intn;printf("Pleaseinputaninteger:");scanf("%d",&n);if(n%2)printf("%dISODD",n);elseprintf("%dISEVEN",n);}7/20/2021Chapter5DecisionMaking