C语言中如何调用文件中的自定义函数
1个回答
展开全部
在主函数中定义即可,如下示例:
#include<stdio.h>
void
main()
{
int
n1,n2;
long
a;
long
sum(int
a,int
b);
long
factorical(int
n);
printf("Enter
n1
and
n2:");
scanf("%d,%d",&n1,&n2);
a=sum(n1,n2);
printf("a=%ld",a);
getch();
}
long
sum(int
a,int
b)
{
long
c1,c2;
c1=factorical(a);/*n1把值传递给a,并调用函数factorical求某个数的阶乘*/
c2=factorical(b);/*n2把值传递给b,并调用函数factorical求某个数的阶乘*/
return
(c1+c2);/*返回c1与c2的和至主函数*/
}
long
factorical(int
n)
{
int
i;
long
rtn=1;
for(i=1;i<=n;i++)
rtn*=i;
return
(rtn);
}
#include<stdio.h>
void
main()
{
int
n1,n2;
long
a;
long
sum(int
a,int
b);
long
factorical(int
n);
printf("Enter
n1
and
n2:");
scanf("%d,%d",&n1,&n2);
a=sum(n1,n2);
printf("a=%ld",a);
getch();
}
long
sum(int
a,int
b)
{
long
c1,c2;
c1=factorical(a);/*n1把值传递给a,并调用函数factorical求某个数的阶乘*/
c2=factorical(b);/*n2把值传递给b,并调用函数factorical求某个数的阶乘*/
return
(c1+c2);/*返回c1与c2的和至主函数*/
}
long
factorical(int
n)
{
int
i;
long
rtn=1;
for(i=1;i<=n;i++)
rtn*=i;
return
(rtn);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询