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: 3926443 • 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.

THIS IS GIVEN:

#include <stdio.h>
#include <stdlib.h>

#define COLS 5

void DisplyArray(int a[][COLS], int rowSize, int colSize)
{
int i, j;

for (i=0 ; ;){ // you need to fix it
for (j=0; ;) // you need to fix it
printf("%d ",a[i][j]);
printf(" ");
}
}

void DoubleArray(int a[][COLS], int rowSize)
{
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( ); // you need to fix it
DoubleArray( ); // you need to fix it
printf("The Array after Doubleing ");
DisplyArray( ); // you need to fix it
  
return 0;
}

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#define COLS 5
void DisplyArray(int a[][COLS], int rowSize, int colSize)
{
int i, j;
for (i=0;i<rowSize;i++){ // loop through rows
for (j=0;j<colSize;j++) // loop through columns
printf("%d ",a[i][j]);
printf(" ");
}
}
void DoubleArray(int a[][COLS], int rowSize)
{
int i,j;
for(i=0;i<rowSize;i++){       // loop through rows
    for(j=0;j<COLS;j++){       // loop through columns
        a[i][j] = a[i][j]*2;   // double the element
    }
}
}

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,3,COLS);        // Pass the array, number of rows, number of columns
DoubleArray(a,3);            // pass the array, number of rows
printf("The Array after Doubeling ");
DisplyArray(a,3,COLS);        // Pass the array, number of rows, number of columns
  
return 0;
}

/* sample output

*/

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