Write a program that declares a 35 array of int and initiali

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\\t\",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;
}

Solution

#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\\t\",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

*/

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 functi
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 functi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site