Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(arrays) dont include. (<stdio.h> only) Multiply each element in origList with t

ID: 3725326 • Letter: #

Question

(arrays) dont include. (<stdio.h> only)

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:

#include <stdio.h>

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

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

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

/* Your solution goes here */

printf(" ");

return 0;
}

Explanation / Answer

/*Array:1. array is fixed size linear data structure which stores homogeneous elements at continuous memory locations.
2. Array support indexing means you can access any element of array using their index
3. array index start from 0 to size-1 , you can see in you array assignment like you have inserted first element at index
0 and last element at index 3 of size 4 array.

So To access each element of array we can use loop which will go from 0 to size-1 and will access element.

So run a for loop from index 0 to 3 and multiply elements at corresponding indexes

like for(i=0;i<3;i++)
origList[i]*offsetAmount[i]

This will multiply elements only at same indexes.

Sample Output :

100 210 120 200

**/

//**************************************************

//copy code from below line to the end of answer to you .c file

//You code start from below line without including #include<stdio.h>

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

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

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

/* Your solution goes here */
//Loop from 0 to NUM_VALS-1 and accessing corresponding elements.
for(i=0;i<NUM_VALS;i++)
{
//Multiplying using * operator and printing on the screen
printf("%d ",(origList[i]*offsetAmount[i]));
}

printf(" ");

return 0;
}