#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;
}
Comments
Leave a comment