- 1、本文档共47页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第7章函数
tiincludeO
int main()
{
void print_star ();
void print_message():
print_star ();
print_message ();
print_star ();
return 0;
}
void print_star()
{
printf(“***********************************\n〃);
}
void print_message()
{
printf(How do you do!\n〃);
}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
How do you do?
從從從冥夫夫夫夫夫关夫夫冥冥*奖冥*冥*冥冥冥冥哭冥龔冥箕彼X
Press any key to continue
int max(int x,int y)
{
int z;
z二xyx:y;
return(z);
}
ttincludeO
int main ()
{
int max(int x,int y);
int a, b, c;
printf (please enter two integer number:,z);
scanf (%d, %d, a, b);
c二max (a, b);
printf(max is %d\n, c);
return 0:
}
please enter two integer number: 1 2,?3坪 max is 12
Press any key to continue
例
ftincludeO int main()
int max(float x,float y);
f loat a, b;
int c;
printf(please enter two integer number:);
scanf (%f, %f, a, b);
c=max (a,b);
printf(max is %d\n, c);
return 0:
}
int max(float x,float y)
{
float z;
z二xyx:y;
return(z);
please enter two in teger n umber- :1? 5,2 ?G max is 2
Press any key to continue.
例
tiincludeO
int main()
float add (float x,float y):
f loat a, b, c;
printf(please enter a and b:〃);
scanf (,z%f, %f, a, b);
c=add(a, b);
printf(sum is %f\n, c);
return 0;
}
float add(float x,float y)
{
float z;
z二x+y;
return (z);
}
please enter a “nd b:3?6.6.5 sum is 10.100000
P“g any key to continue
例
ttincludeO
int main()
{
int max4(int a, int b, int c,int d);
int a, b, c, d, max;
printf (please enter 4 interger number:,z):
scanf (,z%d %d %d %d,z, a, b, c, d);
int max4(int a, int b, int c, int d);
int a, b, c, d, max;
printf(please enter 4 interger number:);
scanf (%d %d %d %d”, a, b, c, d);
max=max4 (a, b, c, d);
pri ntf (max 二%d\r/ \ max);
return 0;
}
int max4(int a, int b, int c,int d)
{
int max2(int a, int b);
return(max2(max2(max2(a, b), c), d));
}
int max2(int a,int b)
{
return(aba:b);
}
例
ttincludeO
int main()
int age(int n):
printf age :%d\nz,, age (5));
return 0:
}
int age (int n)
{
int c;
if(n==l) c=10;
else c二age(n-l)+2;
return(c);
NO.5,age:18
P厂gss any key to continuw
例递归方法求n!
tt
文档评论(0)