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

Add each element in origList with the corresponding value in offsetAmount. Print

ID: 3827535 • Letter: A

Question

Add each element in origList with the corresponding value in offsetAmount. Print each sum followed by a space. Ex: If origList = {40, 50, 60, 70} and offsetAmount = {5, 7, 3.0}, print: 45 57 63 70 #include int int main(void) const int NUM_VALS = 4; int origList [NUM_VALS]; int offsetAmount [NUM_VALS]; int i = 0; origList [0] = 40; origList [1] = 50; origList [2] = 60; origList [3] = 70; offsetAmount [0] = 5; offsetAmount [1] = 7; offsetAmount [2] = 3; offsetAmount [3] = 0;/* Your solution goes here */

Explanation / Answer

#include<stdio.h>
int main(void)
{
   const int NUM_VALS = 4;
   int origList[NUM_VALS];
   int offsetAmount[NUM_VALS];
   int i=0;
  
   origList[0]=40;
   origList[1]=50;
   origList[2]=60;
   origList[3]=70;
  
   offsetAmount[0]=5;
   offsetAmount[1]=7;
   offsetAmount[2]=3;
   offsetAmount[3]=0;
  
   //add offestAmount to origList;
   for(i=0;i<NUM_VALS;i++)
   {
       origList[i]+=offsetAmount[i];  
   }
  
   //DISPLAYING THE OUTPUT
  
   for(i=0;i<NUM_VALS;i++)
   {
       printf("%d ",origList[i]);  
   }
   printf(" ");
}

output:-

45 57 63 70


Process exited with return value 10
Press any key to continue . . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote