Write a program that takes values of a 2D array of 3x3 size and prints the array in matrix form. Like:..
An array of 3x3 size :
4
6
8
12
11
12
10
12
14
// the preprocessing directives
#include<iostream> // cin, cout
#include <iomanip> // setw(n)
using namespace std;
int main( )
{
// declare and initialize variables
int array[3][3];
int i, j; // counters in column and row
// takes values of a 2D array of 3x3 size
cout<<"An array of 3x3 size:"<<endl<<endl;
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
cin>>array[i][j];
cout<<endl;
}
}
// Prints the array in matrix form
cout<<endl<<"An array of 3x3 size:"<<endl;
for(i=0;i<3;i++) {
for(j=0;j<3;j++) {
cout<< setw(4)<<array[i][j];
}
cout<<endl;
}
return 0;
}
Comments
Leave a comment