Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:24:56+00:00 2026-06-17T06:24:56+00:00

Ok, I have another challenge. I have a question that asks me to Read

  • 0

Ok, I have another challenge. I have a question that asks me to “Read a set of integers into a vector. Print the sum of each pair of adjacent elements . Change your program so that it prints out the sum of the first and last elements, followed by the sum of the second and second-to-last, and so on.”

Currently I have managed to get it to add consecutive numbers, not exactly in pairs, but as close as I can get it.

The only operators I have learnt thus far for vectors, and what the question wants me to use are: v.empty(); v.size(); v.push_back(t); v[n]; v1 = v2; v1 = {a,b,c...}; v1 == v2; v1 != v2; <, <=, >, >=

Here is my code as it stands now:

#include <iostream>
#include <string>
#include <vector>

using std::string; using std::vector; using std::cout; using std::cin; using std::endl;

int main ()
{
    vector<unsigned> numbers {5, 6, 7, 8, 9, 10, 11};
    unsigned sum;

    decltype(numbers.size()) count;
    for (count = 0; count < numbers.size(); ++count){
        sum = (numbers[count]++) + (numbers[count]);
        cout << sum << " ";
    }
}

So I can get it to add 5+6; 6+7; 7+8 etc… but as for each pair and all the rest, not 100% sure where to start. Any guidance will be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:24:58+00:00Added an answer on June 17, 2026 at 6:24 am

    Below two loops that print (1) sum of adjacent pairs and (2) the sum of opposite elements.

    #include <cstddef>
    #include <iostream>
    #include <string>
    #include <vector>
    
    using namespace std;
    
    int main ()
    {
        vector<unsigned> numbers {5, 6, 7, 8, 9, 10, 11};
        auto N = numbers.size();
    
        std::cout << "first part\n";
        for (size_t i = 1; i < N; ++i) {
           std::cout << numbers[i-1] + numbers[i] << "\n";
        }
    
        std::cout << "second part\n";
        for (size_t i = 0; i < (N - 1 - i); ++i) {       
          std::cout << numbers[i] + numbers[N - 1 - i] << "\n";   
        }
        // in case you have an odd number of elements
        if (N % 2 == 1) std::cout << numbers[N / 2] << "\n";
    
    }
    

    Output on LiveWorkSpace

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ran into another challenge. I looked through some of the questions that I found
I have another simple question about Node. I'm trying to make a simple http
I have another web app, that uses the liferay user database. But before a
I have another programmer who I'm trying to explain why it is that a
i have another (probably unanswered) question about map views. I have a map view
i have another question on getting my XML serialization neat, which i can't seem
I have another question :(. I'm trying to download multiple files for my application.
I have another XSLT question which follows on from the question I asked last
The Background: I tried to solve the StackOverflow question yet another HTML/CSS layout challenge
I have a challenge in my C# .NET application that I can't figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.