Multiple arrays

Multiply each element in origList with the corresponding value in offsetAmount. Print each product followed by a space.

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

8 20 70 36
#include <stdio.h>

int main(void) {
 const int NUM_VALS = 4;
 int origList[NUM_VALS];
 int offsetAmount[NUM_VALS];
 int i;

origList[0] = 40;
 origList[1] = 10;
 origList[2] = 30;
 origList[3] = 20;

offsetAmount[0] = 5;
 offsetAmount[1] = 7;
 offsetAmount[2] = 3;
 offsetAmount[3] = 4;

int product[NUM_VALS];
 
for(i = 0; i < NUM_VALS; i++){
 product[i] = origList[i] * offsetAmount[i];
 printf("%d ", product[i]);
 }
 printf("\n");

return 0;
}

 

For any element in keysList with a value greater than 60, print the corresponding value in itemsList, followed by a space.
Ex: If keysList = {32, 105, 101, 35} and itemsList = {10, 20, 30, 40}, print:

20 30

solution

#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] > 60){
 printf("%d ",itemsList[i]);
 }
 }

printf("\n");

return 0;
}