Final answer:
To print the corresponding values from itemsList for any element in keysList with a value smaller than 40, you can use a for loop to iterate through the indices of keysList and check if the value is less than 40. If it is, print the corresponding value from itemsList.
Step-by-step explanation:
In this code, we have two arrays: keysList and itemsList. The goal is to iterate through the elements of keysList and print the corresponding values from itemsList if the value in keysList is less than 40.
To achieve this, we can use a for loop that iterates through the indices of keysList. Inside the loop, we can check if the value at the current index is less than 40. If it is, we can print the value at the same index in itemsList, followed by a space.
Here's the modified code:
#include <stdio.h>
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;
for (i = 0; i < SIZE_LIST; i++) {
if (keysList[i] < 40) {
printf("%d ", itemsList[i]);
}
}
return 0;
}
Running this code will produce the output: 12 36