资源描述:
《c语言程序设计课件ppt(英文)c program language 之5 function and program structure》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、FunctionandProgramStructureChapterFourContentsBasicsofFunctions1returnstatements2Localvariablesandexternavariables3Recursion4ScopeRules5HeaderFiles6StaticVariables7RegisterVariables89TheCPreprocessorFunctionandProgramStructure老师让几个同学编程,A负责编写求两个数的最大公约数;B负责两个数的最
2、小公倍数;C负责判断这两个数是不是亲密数;D负责计算这两个数中有多少既能被3整除又能被7整除的数……老师说出了两个数,A,B,C,D立即把自己程序运行的结果告诉老师;老师又说了另外两个数,A,B,C,D又给出新的结果……ABCDmain()(inta,b;scanf(“%d,%d”,&a,&b);funa(a,b);funb(a,b);func(a,b);fund(a,b);}36,120main()(inta,b;scanf(“%d,%d”,&a,&b);funa(a,b);funb(a,b);func(a,b)
3、;fund(a,b);}36,120FunctionandProgramStructureAmain(){inta,b,h;scanf(“%d,%d”,&a,&b);if(a>b){a=a+b;b=a-b;a=a-b;}for(h=a;h>=2;h--)If(a%h==0&&b%h==0)break;printf(“%d,%d,%d”,a,b,h);}funa(inta,intb){inth;if(a>b){a=a+b;b=a-b;a=a-b;}for(h=a;h>=2;h--)If(a%h==0&&b%h==0)
4、break;printf(“%d,%d,%d”,a,b,h);return;}main()(inta,b;scanf(“%d,%d”,&a,&b);funa(a,b);funb(a,b);func(a,b);fund(a,b);}36,120FunctionandProgramStructureCprogramsource1source2source3…...sourcenTheCPreprocessorfunction1function2…...functionnFunctionisthesmallestunit
5、inCprogram.Functiondefinitionscanappearinanyorder,andinonesourcefileorseveralAprogrammayresideinoneormoresourcefiles.Sourcefilesmaybecompiledseparatelyandloadedtogether,alongwithpreviouslycompiledfunctionsfromlibrariesFunctionDeclarationStatementExecutiveState
6、mentVariablesFunctionprototypeVariablestypeVariablenameBlankstatementFunctioncallstatementControlstatementBlockstructureExpressionstatementFunctionandProgramStructureAprogramisjustasetofdefinitionsofvariablesandfunctions.Communicationbetweenthefunctionsisbyarg
7、umentsandvaluesreturnedbythefunctions,andthroughexternalvariables.DefinitionPrototypeCallReturnArgumentsBasicsofFunctions1ThetypesoffunctionsTypeStandardfunctions(library)Needuseheadfiles#include<…..h>User-definedfunctionsEachfunctiondefinitionhastheform2Defin
8、itionofafunctionreturn-typefunction-name(argumentdeclarations){declarationsstatements}ThetypeoftheresultthatthefunctionreturnsparametertypesandnamesIfreturntypeisomitted,intisassum