Write a C++ program to find the sum of all elements of a two-dimensional array A of order M x N .
Answers
Answered by
1
#include iostream.h
#include conio.h
clrscr();
int cols=10;
int rows=10;
int [] [] myArray =new int [cols] [rows];
for(int m=0;m<cols;m+);{
for(int n=0;n<rows;n++);{
myArray[m][n]=int(random(255));
}
}
for(int m=0;m<cols;m+);{
for(int n=0;n<rows;n++);{
stroke(myArray[i][j]);
point(m,n);
}
}
#include conio.h
clrscr();
int cols=10;
int rows=10;
int [] [] myArray =new int [cols] [rows];
for(int m=0;m<cols;m+);{
for(int n=0;n<rows;n++);{
myArray[m][n]=int(random(255));
}
}
for(int m=0;m<cols;m+);{
for(int n=0;n<rows;n++);{
stroke(myArray[i][j]);
point(m,n);
}
}
Answered by
1
#include <iostream>
using std::cout;
int main()
{
int array[m][n], columntotal[n] = {0}, rowtotal[m] = {0};
int x, y, z = 1; //x & y are iterate around loops, z to fill up the array with some numbers.
for(x = 0; x < m; ++x) //Just fill up the array with some numbers.
{
for(y = 0; y < n; ++y)
{
array[m][n] = z;
++z;
}
}
for(x = 0; x < n; ++x) //Sum the columns.
{
for(y = 0; y < m; ++y)
{
columntotal[n] = columntotal[n] + array[m][n];
}
}
for(x = 0; x < n; ++x) //Output of each column.
{
cout << columntotal[n] << "\n";
}
return 0;
}
Similar questions