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
#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;
}
Comments
Leave a comment