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

Given an ARRAY: table[3][4] Use any 12 random integer numbers for a table as sho

ID: 3766478 • Letter: G

Question

Given an ARRAY: table[3][4]

Use any 12 random integer numbers for a table as shown below. Write a C program to provide and print the sum of the rows.

what i got so far:

#include <stdio.h>

int main(void)
{
   char exit;
   int r, c=0;
   int sum[3];
   int table[3][5] = {
       { 0, 1, 2, 3 },
       { 4, 5, 6, 7 },
       { 8, 9, 10, 11 }
   };

   for (r = 0; r < 4; c++) {
       sum[r] = 0;
       for (c = 0; c < 5; c++)
       sum[r] = sum[r] + table[r][c];
       table[r][5] = sum[r];
   }
   for (r = 0; r < 3; r++)
       for (c = 0; c < 5; c++)
   printf("the sum is %d", sum[r]);
   scanf(" %c", &exit);
   return(0);
  
}

Explanation / Answer

#include <stdio.h>
int main(void) {
int r, c=0;
int sum[3];
int table[3][4] = {
{ 0, 1, 2, 3 },
{ 4, 5, 6, 7 },
{ 8, 9, 10, 11 }
};
for (r = 0; r < 3; r++) {
sum[r] = 0;
for (c = 0; c < 4; c++)
sum[r] = sum[r] + table[r][c];
}
for (r = 0; r < 3; r++)
printf("the sum of row %d is %d ",r, sum[r]);
   return 0;
}

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