For any element in keysList with a value smaller than 40, print the corresponding value in itemsList, followed by a space.

Ex: If keysList = {32, 105, 101, 35} and itemsList = {10, 20, 30, 40}, print:


10 40


#include int main (void) { const int SIZE_LIST = 4; int keysList[SIZE_LIST]; int itemsList[SIZE_LIST]; int i; keysList[0] = 13; keysList[1] = 47; keysList[2] = 71; keysList[3] = 59; itemsList[0] = 12; itemsList[1] = 36; itemsList[2] = 72; itemsList[3] = 54; //Loop from 0 to NUM_VALS-1 and accessing corresponding elements. for(i=0;i

Respuesta :

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.    const int SIZE_LIST = 4;
  6.    int keysList[SIZE_LIST];
  7.    int itemsList[SIZE_LIST];
  8.    int i;
  9.    keysList[0] = 13;
  10.    keysList[1] = 47;
  11.    keysList[2] = 71;
  12.    keysList[3] = 59;
  13.    itemsList[0] = 12;
  14.    itemsList[1] = 36;
  15.    itemsList[2] = 72;
  16.    itemsList[3] = 54;
  17.    
  18.    for(i=0; i < SIZE_LIST; i++){
  19.        
  20.        if(keysList[i] < 40){
  21.            cout<<itemsList[i]<< " ";    
  22.        }
  23.    }
  24.    return 0;
  25. }

Explanation:

In the given code we have two parallel arrays with predefined values (Line 11 - 18). To check if any value from keysList below 40, create a for loop to traverse through the array and in the loop create an if statement to check the each of the keysList value (Line 20 - 22). If any value from keysList is below 40, use the current i value as an index to get the corresponding value from itemsList (Line 23) and print it out along with a single space " ".