Answer to Question #260514 in C++ for malika

Question #260514

Multiply each element in origList with the corresponding value in offsetAmount. Print each product followed by a semicolon (no spaces).


Ex: If origList = {4, 5, 10, 12} and offsetAmount = {2, 4, 7, 3}, print:

8;20;70;36;


#include <iostream>

#include <string.h>

using namespace std;


int main() {

  const int NUM_VALS = 4;

  int origList[NUM_VALS];

  int offsetAmount[NUM_VALS];

  int i;


  cin >> origList[0];

  cin >> origList[1];

  cin >> origList[2];

  cin >> origList[3];


  cin >> offsetAmount[0];

  cin >> offsetAmount[1];

  cin >> offsetAmount[2];

  cin >> offsetAmount[3];


  /* Your code goes here */


  cout << endl;


  return 0;

}


1
Expert's answer
2021-11-05T17:29:39-0400
#include <iostream>


#include <string.h>


using namespace std;






int main() {


  const int NUM_VALS = 4;


  int origList[NUM_VALS];


  int offsetAmount[NUM_VALS];


  int i;






  cin >> origList[0];


  cin >> origList[1];


  cin >> origList[2];


  cin >> origList[3];






  cin >> offsetAmount[0];


  cin >> offsetAmount[1];


  cin >> offsetAmount[2];


  cin >> offsetAmount[3];






  /* Your code goes here */
    for(int i=0;i<4;i++){
        cout<<(origList[i]*offsetAmount[i])<<";";
    }




  cout << endl;






  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