Menu

[Solved]Please Use C Fill Code Program Hardcode Array Indexes Instead Use Loops Variables Include Q37065037

Please Use C++.

Fill in the code for the below program. Do not hardcode thearray indexes but instead use loops and variables.

#include <iostream>
using namespace std ;

const int ROWS = 4 ;
const int COLS = 4 ;

//Change the array such that every value is squared
//If the value is 2 then that value changes to 4
//If the value is 3 then that value becomes 9

void squareTheArray( int arr1[ROWS][COLS] )
{
//To Do

}

void printArray( int arr1[ROWS][COLS] )
{
cout << “Printing the Array,” << endl ;
for( int i1=0 ; i1 < ROWS ; i1++ )
{
       for( int j1=0 ; j1< COLS ;j1++ )
            cout << arr1[i1][j1] << “,” ;
        cout << endl;
   } //for
cout << endl ;
}

//Left Diagonal is the diagonal that runs from 0,0 to 3,3
void printSumLeftDiagonal( int arr1[ROWS][COLS] )
{
//To do
}

//Right Diagonal is the diagonal that runs from 0,3 to 3,0
void printSumRightDiagonal( int arr1[ROWS][COLS] )
{
//To do

}

int main()
{
int array1[4][4] = { { 1, 2 , 3 , 4 } ,
{ 5, 6 , 7 , 8 } ,
{ 9, 10 , 11 , 12 } ,
{ 13, 14 , 15 , 16 } } ;

squareTheArray( array1 ) ;
printArray( array1 ) ;
printSumLeftDiagonal( array1 ) ;
printSumRightDiagonal( array1 ) ;

}

Your output should display:

Printing the Array,
1,4,9,16,
25,36,49,64,
81,100,121,144,
169,196,225,256,

sumLeftDiagonal:414
sumRightDiagonal:334

Expert Answer


Answer to Please Use C++. Fill in the code for the below program. Do not hardcode the array indexes but instead use loops and vari… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *