我在做一道简单的初学编程题目,是求n1~n2的累加和,可是出现了一个错误,求高手指点,谢谢 20
程序:intSuml(intn1,n2){inti,sum;sum=0;for(i=n1;i<=n2;i=i+1)sum=sum+i;returnsum;}#includ...
程序:
int Suml(int n1,n2)
{
int i,sum;
sum=0;
for(i=n1;i<=n2;i=i+1)
sum=sum+i;
return sum;
}
#include<stdio.h>
void main(void)
{
int n1,n2,sum;
printf("请输入数值n1:");
scanf ("%d",&n1);
printf("请输入数值n2:");
scanf ("%d",&n2);
sum=Suml(n1,n2);
printf("n1—n2的累加和为%d",sum);
}
错误:C:\Documents and Settings\Administrator\桌面\Text4.c(1) : error C2081: 'n2' : name in formal parameter list illegal
Error executing cl.exe. 展开
int Suml(int n1,n2)
{
int i,sum;
sum=0;
for(i=n1;i<=n2;i=i+1)
sum=sum+i;
return sum;
}
#include<stdio.h>
void main(void)
{
int n1,n2,sum;
printf("请输入数值n1:");
scanf ("%d",&n1);
printf("请输入数值n2:");
scanf ("%d",&n2);
sum=Suml(n1,n2);
printf("n1—n2的累加和为%d",sum);
}
错误:C:\Documents and Settings\Administrator\桌面\Text4.c(1) : error C2081: 'n2' : name in formal parameter list illegal
Error executing cl.exe. 展开
4个回答
展开全部
#include<stdio.h>
int Suml(int n1,int n2) //这里
{
int i,sum;
sum=0;
for(i=n1;i<=n2;i=i+1)
sum=sum+i;
return sum;
}
void main(void)
{
int n1,n2,sum;
printf("请输入数值n1:");
scanf ("%d",&n1);
printf("请输入数值n2:");
scanf ("%d",&n2);
sum=Suml(n1,n2);
printf("n1—n2的累加和为%d",sum);
}
int Suml(int n1,int n2) //这里
{
int i,sum;
sum=0;
for(i=n1;i<=n2;i=i+1)
sum=sum+i;
return sum;
}
void main(void)
{
int n1,n2,sum;
printf("请输入数值n1:");
scanf ("%d",&n1);
printf("请输入数值n2:");
scanf ("%d",&n2);
sum=Suml(n1,n2);
printf("n1—n2的累加和为%d",sum);
}
展开全部
开头就错了
应该是int Suml(int n1,int n2)
n2前面没定义
应该是int Suml(int n1,int n2)
n2前面没定义
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一楼正解......
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询