c语言关于外部函数调用的一道题

来源:百度知道 编辑:UC知道 时间:2024/06/30 09:00:08
(2)练习如何运行一个多文件的程序:
file1编写一个函数实现1+2+3+…+n
file2编写一个函数(用递归方法)实现 n!
file3编写一个程序输入一个n的数值将
上述两个函数的值相加并将结果输出。
我的file1:
/*编写一个函数实现1+2+3+…+n*/
#include<stdio.h>

a(int x)
{
int i,ta=0;

for(i=1;i<=x;i++)
ta=ta+i;

return(ta);
}
file2:
/*编写一个函数(用递归方法)实现 n! */
#include<stdio.h>
int b(int x)
{
int i,tb;
if(x==0)
return(1);
else
{
for(i=1;i<=x;i++)
tb=x*b(x-1);

return(tb);
}

}
file3应该怎么做呢?
beanee朋友的回答会报错:
--------------------Configuration: Cpp3 - Win32 Debug--------------------
Compiling...
Cpp3.cpp
C:\Documents and Settings\Administrator\My Documents\c\c8014gws\Cpp3.cpp(7) : error C2065: 'a' : undeclared identifier
C:\Documents and Settings\Administrator\My Documents\c\c8014gws

// file3.c
#include <stdio.h>
int a(int x);
int b(int x);
int main()
{
int x;
int result;
printf("Input x:");
scanf("%d", &x);
result = a(x) + b(x);
printf("result = %d\n", result);
}

#include <stdio.h>
void function3()
{
int n;
printf("Input n:");
scanf("%d", &n);
int result = a(n) + b(n);
printf("result = %d\n", result);
}