资源描述:
《chap_用c语言编写程序(chap_ programs written in c language)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、chap02_用c语言编写程序(Chap02_programswritteninClanguage)Chap2programswritteninClanguage2.1displaysHelloWorldonthescreen!2.2,Fahrenheittemperatureof100degreesCelsiusFCelsiustemperature2.3calculatepiecewisefunctions2.4outputFahrenheitCelsiustemperatureconversiontableThe2.5generati
2、onpowertableandtableoffactorialsMainpointsofthischapterHowdoyouwriteprogramsanddisplaysomeinformationonthescreen?Howdoyouwriteprogramsthatimplementsimpledataprocessing,suchasconvertingFahrenheittoCelsius?HowdoIuseifstatementstocalculatesegmentationfunctions?HowdoIrequest1+
3、2+withtheforstatement?......+100?Howtodefineandcallthefunctiontogenerateapowertable?2.1displaysHelloWorldonthescreen!Example2-1showsashortsentenceonthescreen:HelloWorld!2.1displaysHelloWorldonthescreen!*display"HelloWorld!"*/commenttext#includeIntmain(void)primary
4、function{Printf("Hello,World,");statementendedReturn0;}Outputfunctionlinebreak2.1displaysomeinformationonthescreenExample2-2isdisplayedonthescreen:Programmingisfun!And,Programming,in,C,is,even,more,fun!#includecompilerpreprocessorIntmain(void){Printf("Programmin
5、g,is,fun,");Printf(And,Programming,in,C,is,even,more,fun,);Return0;}2.2,Fahrenheittemperatureof100degreesCelsiusFCelsiustemperatureThetemperatureisC=(5/9)(F-32)2.2.1programanalysis2.2.2constants,variables,anddatatypes2.2.3arithmeticoperationsandassignmentoperations2.2.
6、4formatoutputfunctionprintf2.2.1programanalysisExample2-3forFahrenheittemperature100degreesFCelsiustemperature.ThetemperatureisC=(5/9)(F-32)#includeIntmain(void){Int,Celsius,Fahr;variabledefinitionsFahr=100;variableusageCelsius=5*(Fahr-32)/9;Printf("Fahr=%d,Celsiu
7、s=%d","Fahr","Celsius");outputresultsReturn0;}2.2.2constants,variables,anddatatypesInt,Celsius,fahr;Celsius=5*(Fahr-32)/9;dataConstant:thevalueofaprogramcannotbechangedduringtheprogram'soperationVariable:thevalueofaprogramcanbechangedduringtherunoftheprogramdatatypeConst
8、ants:5and9areintegerconstants(integers)Variable:specifiedatdefinitionDefinitionofvariable