作业帮 > 综合 > 作业

c++输入一组整数,把相邻的两个数相加

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 20:05:09
c++输入一组整数,把相邻的两个数相加
#include
#include
#include
using namespace std;
int main(void)
{
vector text;
int value;
int temp;
vector::size_type t;
while(cin>>value)
text.push_back(value);
if(text.size()%2==0)
{
for(t=0;t!=text.size()-1;t=t+2)
{
temp=text[t]+text[t+1];
cout
测试通过
请采纳!

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void)
{
    vector<int> text;
    int value;
    int temp;
    vector<int>::size_type t;
    while(cin>>value)
  text.push_back(value);
  if(text.size()%2==0)
  {
   for(t=0;t<=text.size()-1;t=t+2)  //这里改为小于等于
   {
    temp=text[t]+text[t+1];
    cout<<temp<<endl;
   }
  }
}
再问: 尼编译过了吗
再问: 改了,没用
再答: 测试通过,可以看到结果

你要这样输入
1
2
3
4
ctrl+z 回车

出结果
再问:
再问: 我改了输入没反应
再答: 键盘上再按ctrl+z 同时按,回车
再问: ok,为什么啦?
再答: 流的结束标记 记住就可以了
再问: 对了,为什么那里用!=是错的。
再问: 再帮我解答下,谢谢
再问: 能不能讲解一下啊,不胜感激啊