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

Write a program that declares a 3×5 array of int and initializes it to some valu

ID: 3926452 • Letter: W

Question

Write a program that declares a 3×5 array of int and initializes it to some values of your choice. - Write a function to do the displaying and - a second function to do the doubling.

Have the functions take the array name and the number of rows as arguments.

#include <stdio.h>

#include <stdlib.h>

#define ROWS 3

#define COLS 5

void DisplyArray(int a[][COLS], int rowSize, int colSize)

{

int i, j;

for (i=0 ; ; ){

for (j = 0; ; )

printf("%d ",a[i][j]);

printf(" ");

}

}

void DoubleArray(int (*a)[COLS], int rowSize, int colSize)

{

int i, j;

}

int main()

{

int a[][COLS]={{13, 24, 77, 78, 19},

{20, 18, 36, 48, 87},

{87, 43, 29, 12, 34}};

printf("The Original Array ");

DisplyArray( );

DoubleArray( );

printf("The Array after Doubleing ");

DisplyArray( );

  

return 0;

}

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

#define ROWS 3

#define COLS 5

void DisplyArray(int a[][COLS], int rowSize, int colSize)

{

   int i, j;

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

      for (j = 0; j < colSize; ++j )

         printf("%d ",a[i][j]);

      printf(" ");

   }

}

void DoubleArray(int (*a)[COLS], int rowSize, int colSize)

{

   int i, j;
   for(i=0;i<rowSize;++i)
     {
       for(j=0;j<colSize;j++)
   a[i][j]=2*a[i][j];
     }

}

int main()

{

   int a[][COLS]={{13, 24, 77, 78, 19},

             {20, 18, 36, 48, 87},

             {87, 43, 29, 12, 34}};

   printf("The Original Array ");

   DisplyArray(a,ROWS, COLS);

   DoubleArray(a, ROWS, COLS);

   printf("The Array after Doubleing ");

   DisplyArray(a, ROWS, COLS);

  

   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