C++代码 用VS2010一运行输入数据后就出错
输入2个数,求两个数之间的自然数之和。#include<iostream>usingnamespacestd;intmain(){intv1,v2;cout<<"Ente...
输入2个数,求两个数之间的自然数之和。
#include <iostream>
using namespace std;
int main()
{
int v1,v2;
cout<<"Enter two numbers : "<<endl;
cin>>v1>>v2;
int upper,lower;
if(v1 >= v2)
{
v1 = upper ;
v2 = lower;
}
else
{
v1 = lower;
v2 = upper;
}
int sum = 0;
int val = lower;
while(val <= upper)
{
sum += val;
++val;
}
cout<<"The sum of lower to upper inclusive is "<<sum<<endl;
return 0;
} 展开
#include <iostream>
using namespace std;
int main()
{
int v1,v2;
cout<<"Enter two numbers : "<<endl;
cin>>v1>>v2;
int upper,lower;
if(v1 >= v2)
{
v1 = upper ;
v2 = lower;
}
else
{
v1 = lower;
v2 = upper;
}
int sum = 0;
int val = lower;
while(val <= upper)
{
sum += val;
++val;
}
cout<<"The sum of lower to upper inclusive is "<<sum<<endl;
return 0;
} 展开
2个回答
展开全部
#include <iostream>
using namespace std;
int main()
{
int v1,v2;
cout<<"Enter two numbers : "<<endl;
cin>>v1>>v2;
int upper,lower;
if(v1 >= v2)
{
upper=v1 ;
lower=v2;
}
else
{
lower=v1;
upper=v2;
}
int sum = 0;
int val = 伏罩lower;
while(val <= upper)
{
sum += val;
++val;
}
cout<<"The sum of lower 察厅链败孙to upper inclusive is "<<sum<<endl;
return 0;
}
修改代码如上,你搞反了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
using namespace std;
int main()
{
int v1,v2;
cout<<"Enter two numbers : "<<endl;
cin>>v1>>v2;
int upper,lower;
if(v1 >= v2)
{
upper=v1 ;
lower=v2 ;
}
else
{
upper=v2 ;
lower=v1 ;
}
int sum = 0;
int val = lower;
while(val <= upper)
{
sum += val;
++val;
}
cout<亩宴<"链灶The sum of lower to upper inclusive is "<<棚耐扮sum<<endl;
return 0;
}
using namespace std;
int main()
{
int v1,v2;
cout<<"Enter two numbers : "<<endl;
cin>>v1>>v2;
int upper,lower;
if(v1 >= v2)
{
upper=v1 ;
lower=v2 ;
}
else
{
upper=v2 ;
lower=v1 ;
}
int sum = 0;
int val = lower;
while(val <= upper)
{
sum += val;
++val;
}
cout<亩宴<"链灶The sum of lower to upper inclusive is "<<棚耐扮sum<<endl;
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询