c语言中用户自定义函数的格式是什么?

如题所述

c语言中用户自定义函数的格式:
函数返回类型
函数名(参数列表)
{
代码段;
return
函数返回值;
}
例如:
int test(int value)
{
value += 10;
return value;
}
上面示例定义了一个名为test的函数,其返回值为int型,参数为int型,返回值为参数与10之和。
注:函数类型为void时,不可有return语句。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-05-24
来个样例程序(输入两个数,求
最大公约数

#include
<stdio.h>
#include
<stdlib.h>
int
a,b;
int
gcd(int
x,int
y)
{
if
(x%y==0)
return
y;
else
return
gcd(y,x%y);
}
int
main()
{
scanf("%d%d",&a,&b);
printf("%d\n",gcd(a,b));
return
0;
}
第2个回答  2019-05-25
来个样例程序(输入两个数,求最大公约数)
#include
<stdio.h>
#include
<stdlib.h>
int
a,b;
int
gcd(int
x,int
y)
{
if
(x%y==0)
return
y;
else
return
gcd(y,x%y);
}
int
main()
{
scanf("%d%d",&a,&b);
printf("%d\n",gcd(a,b));
return
0;
}