求教一道C语言题目,谢谢大家啦!!
#include<stdio.h>main(){inta,b,c;a=5,b=3;c=sum(a,b);printf("%d+%d=%d\n",a,b,c);}sum(x...
#include <stdio.h>
main()
{ int a,b,c;
a=5,b=3;
c=sum(a,b);
printf("%d+%d=%d\n",a,b,c);
}
sum(x,y)
int x,y;
{
return(x+y);
}
编写下来后有五个错误,我看不懂了。。。
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(5) : error C2065: 'sum' : undeclared identifier
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(7) : warning C4508: 'main' : function should return a value; 'void' return type assumed
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(8) : error C2065: 'x' : undeclared identifier
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(8) : error C2065: 'y' : undeclared identifier
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(9) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(9) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Cpp1.obj - 5 error(s), 1 warning(s) 展开
main()
{ int a,b,c;
a=5,b=3;
c=sum(a,b);
printf("%d+%d=%d\n",a,b,c);
}
sum(x,y)
int x,y;
{
return(x+y);
}
编写下来后有五个错误,我看不懂了。。。
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(5) : error C2065: 'sum' : undeclared identifier
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(7) : warning C4508: 'main' : function should return a value; 'void' return type assumed
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(8) : error C2065: 'x' : undeclared identifier
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(8) : error C2065: 'y' : undeclared identifier
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(9) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
D:\QMDownload\Microsoft Visual Studio\Visual C++ 6.0(完整绿色版)\Cpp1.cpp(9) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Cpp1.obj - 5 error(s), 1 warning(s) 展开
3个回答
展开全部
程序修改一下:
#include <stdio.h>
main()
{
int sum(int x,int y);//加一个函数声明,因为你的函数在后面实现,但你要提前用
int a,b,c;
a=5;//这儿要修改
b=3;
c=sum(a,b);
printf("%d+%d=%d\n",a,b,c);
}
int sum(int x,int y)// sum函数需要返回值类型int ,和形式参数 int x和int y sum(x,y)
// 去掉 int x,y;
{
return(x+y);
}
#include <stdio.h>
main()
{
int sum(int x,int y);//加一个函数声明,因为你的函数在后面实现,但你要提前用
int a,b,c;
a=5;//这儿要修改
b=3;
c=sum(a,b);
printf("%d+%d=%d\n",a,b,c);
}
int sum(int x,int y)// sum函数需要返回值类型int ,和形式参数 int x和int y sum(x,y)
// 去掉 int x,y;
{
return(x+y);
}
展开全部
#include <stdio.h>
int sum(int x,int y) ; //先声明一下
main()
{ int a,b,c;
a=5;b=3; //中间不是逗号,是分号
c=sum(a,b);
printf("%d+%d=%d\n",a,b,c);
}
sum(x,y)
int x,y;
{
return(x+y);
}
int sum(int x,int y) ; //先声明一下
main()
{ int a,b,c;
a=5;b=3; //中间不是逗号,是分号
c=sum(a,b);
printf("%d+%d=%d\n",a,b,c);
}
sum(x,y)
int x,y;
{
return(x+y);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把sum定义到main函数前
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询