Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

SOURCE CODE:

//Array index always starts with zero.


#include<iostream>
using namespace std;

main(){
int x, y, sum;
int num[3][3]={{2,2,3},{1,1,3},{3,2,3}};

//DISPLAY
cout<<("Numbers\n\n");
for(x=0; x<=2; x++)
{ for(y=0; y<=2; y++)
cout<<"\t"<<num[x][y];
cout<<"\n";
}

//sum all
sum=0;
for(x=0; x<=2; x++)
for(y=0; y<=2; y++)
sum = sum+num[x][y];

//cout<<"\n ";
cout<<"\nThe sum of all numbers = "<< sum;

//SUBSCRIPT 00 01 02
sum=0;
x=0;
for(y=0; y<=2; y++)
{ sum = sum +num[x][y]; }
cout<<"\n\n The sum of row [0] &subscript [00 01 02] = " <<sum;

//The sum of row [1] &subscript [10 11 12]


sum=0;
x=1;
for(y=0; y<=2; y++)
{ sum = sum +num[x][y]; }
cout<<"\n\n The sum of row [1] &subscript [10 11 12] = " <<sum;

//The sum of row [2] &subscript [20 21 22]


sum=0;
x=2;
for(y=0; y<=2; y++)
{ sum = sum +num[x][y]; }
cout<<"\n\n The sum of row [2] &subscript [20 21 22] = " <<sum;

//The sum of column[0] & subscript [00 10 20]


sum=0;
y=0;
for(x=0; x<=2; x++)
{ sum = sum +num[x][y]; }
cout<<"\n\n The sum of column[0] & subscript [00 10 20] = " <<sum;

//The sum of column[1] &subscript [01 11 21]


sum=0;
y=1;
for(x=0; x<=2; x++)
{ sum = sum +num[x][y]; }
cout<<"\n\n The sum of column[1] &subscript [01 11 21] = " <<sum;

//The sum ofcolumn[2] & subscript [02 12 22]


sum=0;
y=2;
for(x=0; x<=2; x++)
{ sum = sum +num[x][y]; }
cout<<"\n\n The sum ofcolumn[2] & subscript [02 12 22] = " <<sum;

// The sum of diagonal 1 & subscript [00 11 22]


sum=0;
for(x=0; x<=2; x++){
for(y=0; y<=2; y++)
if(x==y)
{ sum = sum +num[x][y]; }
}
cout<<"\n\n The sum of diagonal 1 & subscript [00 11 22] = " <<sum;

// The sum of diagonal 2 & subscript [20 11 02]


sum=0;
for(x=0; x<=2; x++){
for(y=0; y<=2; y++)
if(x+y==2)
{ sum = sum +num[x][y]; }
}
cout<<"\n\n The sum of diagonal 2 & subscript [20 11 02] = " <<sum;

OUTPUT:

You might also like