Answer to Question #322682 in C++ for Program Training

Question #322682

Add each element in origList with the corresponding value in offsetAmount. Print each sum followed by a space. Ex: If origList = {40, 50, 60, 70} and offsetAmount = {5, 7, 3, 0}, print: 

45 57 63 70




1
Expert's answer
2022-04-02T19:08:22-0400
#include <iostream>
using namespace std;

int main() 
{
    int i;
    int size;

    cout << "Enter the size of two arrays: ";
    cin >> size;

    int* origList = new int[size];
    int* offsetAmount = new int[size];

    cout << "\nEnter the numbers of 'OrigList': " << "\n";
    
    for (i = 0; i < size; i++)
    {
        cin >> origList[i];
    }

    cout << "\nOrigList: ";

    for (i = 0; i < size; i++)
    {
        cout << origList[i] << ' ';
    }

    cout << "\n\nEnter the numbers of 'OffsetAmount': " << "\n";

    for (i = 0; i < size; i++)
    {
        cin >> offsetAmount[i];
    }

    cout << "\nOffsetAmount: ";

    for (i = 0; i < size; i++)
    {
        cout << offsetAmount[i] << ' ';
    }

    cout << "\n\nSum: ";

    for (i = 0; i < size; i++)
    {
        cout << origList[i] + offsetAmount[i] << ' ';
    }

    cout << "\n";

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS