/*
* Copyright (c) 2012, computer College, Yantai University
* All rights reserved.
* File name: Two-dimensional array. cpp
* Author: Qiu xuewei
* Completion date: January 1, December 7, 2012
* Version No.: v1.0
*
* Input Description: None
* Problem description: defines two-dimensional arrays, assigns initial values, input values, and change values to dimension arrays, and outputs data by various methods.
* Program output: omitted
* Problem Analysis: omitted
* Algorithm Design: omitted
*/
# Include <iostream>
Using namespace std;
Int main ()
{
Int I, j;
Int a [5] [4] = {0, 1}, {4, 5}, {8, 9}, {12, 13}, {16, 17 }};
Cout <"Enter 10 integers:" <endl;
For (I = 0; I <5; I ++)
{
For (j = 2; j <4; j ++)
Cin> a [I] [j];
}
// Output in the order of rows first
Cout <"the value in the array is:" <endl;
For (I = 0; I <5; I ++)
{
Cout <"no." <I <"row:" <'\ T ';
For (j = 0; j <4; j ++)
{
Cout <a [I] [j] <'\ T ';
If (j = 3)
Cout <endl;
}
} Cout <"the value after the array is multiplied by 3 is:" <endl;
// Multiply all elements by 3 and save them in the array
For (I = 0; I <5; I ++)
{
For (j = 0; j <4; j ++)
A [I] [j] = a [I] [j] * 3;
}
For (I = 0; I <5; I ++)
{
Cout <"no." <I <"row:" <'\ T ';
For (j = 0; j <4; j ++)
{
Cout <a [I] [j] <'\ T ';
If (j = 3)
Cout <endl;
}
}
Cout <"column order first output:" <endl;
For (j = 0; j <4; j ++)
{
Cout <"no." <j <"column:" <'\ T ';
For (I = 0; I <5; I ++)
{
Cout <a [I] [j] <'\ T ';
If (I = 4)
Cout <endl;
}
}
Cout <"inverted output:" <endl;
For (I = 4; I> = 0; I --)
{
Cout <"no." <I <"row:" <'\ T ';
For (j = 3; j> = 0; j --)
{
Cout <a [I] [j] <'\ T ';
If (j = 0)
Cout <endl;
}
}
Cout <"an even number in the array:" <endl;
For (I = 0; I <5; I ++)
{
For (j = 0; j <4; j ++)
If (a [I] [j] % 2 = 0)
Cout <"a [" <I <"] [" <j <"]" <"=" <a [I] [j] <endl;
}
Cout <"The sum of row and column subscripts is a multiple of 3:" <endl;
For (I = 0; I <5; I ++)
{
For (j = 0; j <4; j ++)
If (I + j) % 3 = 0)
Cout <"a [" <I <"] [" <j <"]" <"=" <a [I] [j] <endl;
}
Return 0;
}