221k views
1 vote
Multiply each element in origList with the corresponding value in offsetAmount. Print each product followed by a semicolon (no spaces). Ex: If the input is: 4 5 10 12 2 4 7 3 the output is: 8; 20;70; 36; 1 #include 2 3 int main(void) { 4 const int NUM_VALS = 4; 5 int origList[NUM_VALS]; 6 int offsetAmount [NUM_VALS]; 7 int i; 8 9 scanf("%d", &origList[0]); 10 scanf("%d", &origList[1]); 11 scanf("%d", &origList[2]); 12 scanf("%d", &origList[3]); 13 14 scanf("%d", &offsetAmount[0]); 15 scanf("%d", &offsetAmount[1]); 16 scanf("%d", &offsetAmount[2]); 17 scanf("%d", &offsetAmount[3]); 18 19 \* Your code goes here */ 20 21 printf("\\"); 22 23 return 0; 24

User Nicover
by
4.5k points

1 Answer

3 votes

Answer:

Replace /* Your code goes here */ with

for(i =0; i<NUM_VALS; i++) {

printf("%d", origList[i]*offsetAmount[i]);

printf(";");

}

Step-by-step explanation:

The first line is an iteration statement iterates from 0 till the last element in origList and offsetAmount

for(i =0; i<NUM_VALS; i++) {

This line calculates and print the product of element in origList and its corresponding element in offsetAmount

printf("%d", origList[i]*offsetAmount[i]);

This line prints a semicolon after the product has been calculated and printed

printf(";");

Iteration ends here

}

User Psychowood
by
4.3k points