Question #100724

Write a program that asks the user to enter integer numbers and store the numbers in a two-dimensional array,thenreplaceany9digitby0digit.Afterthatreplacethenumberswiththeodd

summations indices by the even summation indices.

Expert's answer

#include <iostream>

#define num 4

using namespace std;


int main()

{

cout << "Enter integers (16):" << endl;

int arr[num][num];

int i;

for (i = 0; i < 4; i++)

{

int j = 0;

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

{

cin >> arr[i][j];

}

}

cout << "\nYour array:" << endl;

for (i = 0; i < 4; i++)

{

int j = 0;

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

{

cout << arr[i][j] << " ";

}

cout << endl;

}

cout << "\nYour new array (changed 9 to 0):" << endl;

for (i = 0; i < 4; i++)

{

int j = 0;

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

{

if (arr[i][j] == 9) arr[i][j] = 0;

cout << arr[i][j] << " ";

}

cout << endl;

}

cout << "\nYour final array (changed 9 to 0, then all numbers with the odd summations indices replaced by arr[1][1]):" << endl;

for (i = 0; i < 4; i++)

{

int j = 0;

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

{

if ((i+j)%2 == 1) arr[i][j] = arr[0][0];

cout << arr[i][j] << " ";

}

cout << endl;

}

system("pause");

return 0;

}


LATEST TUTORIALS
APPROVED BY CLIENTS