MultiDimensional Array
/* kindly correct my program - print respective elements and their indexes also sum up them using loops?*/ #include <iostream> using namespace std; int main() { /*int arrTelNum[5]={3,5,7,9,11}; int sum=0; for (int x=0; x<5; x++){ sum = sum+arrTelNum[x]; cout<<x<<" :"<<arrTelNum[x]<<endl; } cout<<"Total array indexes are: "<<arrTelNum[5]<<" and sum of values is: "<<sum<<endl; */ int array1[9]={2,4,5,-6,-8,9,-22,80,-45}; int arrSum1=0; cout<<"Index"<<" : "<<"Array Element"<<endl; for (int x=0; x<9; x++){ arrSum1 += array1[x]; cout<<x <<" : "<<array1[x]<<endl; } cout<<"Total number of indexes of first array are: "<<array1[9]<<endl; cout<<" And sum of array elements of first array is: "<<arrSum1<<endl; /*---------------------------------------------------------------------*/ /* Multidimesional Array */ int arrMulti2Dim [3][3]={{2,1,3},{3,4,5},{2,5,6}}; int i; int j; int sumMulti2Dim =0; cout<<"Element at index dimension 0x0 is: "<<arrMulti2Dim[0][0] <<endl; cout<<"Element at index dimension 0x1 is: "<<arrMulti2Dim[0][1] <<endl; cout<<"Element at index dimension 0x1 is: "<<arrMulti2Dim[0][2] <<endl; cout<<"Element at index dimension 0x1 is: "<<arrMulti2Dim[1][0] <<endl; cout<<"Element at index dimension 0x1 is: "<<arrMulti2Dim[1][1] <<endl; cout<<"Element at index dimension 0x1 is: "<<arrMulti2Dim[1][2] <<endl; cout<<"Element at index dimension 0x1 is: "<<arrMulti2Dim[2][0] <<endl; cout<<"Element at index dimension 0x1 is: "<<arrMulti2Dim[2][1] <<endl; cout<<"Element at index dimension 0x1 is: "<<arrMulti2Dim[2][2] <<endl; cout<<"Index"<<" : "<<"Array Element"<<endl; /* for (i=0 && j=0; i<3 && j<3; i++ && j++){ arrMulti2Dim += arrMulti2Dim; cout <<i , j<<" : "<<arrMulti2Dim[3][3]<<endl;