Calculate a massive A[n][m] elements which are randomized within the interval of [-5, 5], n and m, is inputted by user. Afterwards get all the positive numbers from each line and calculate the median.

 ``123456789101112131415161718192021222324252627282930313233`` ``````#include #include #include #include int main () { randomize(); int a[20][20], n, m; int i,j,sum=0, sum1=0; cout<<"Input n "; cin>>n; cout<<"Input m "; cin>>m; for(i=0; i0) sum=sum1+a[i][j]; }cout<

Its not doing the if im asking and doesn't calculate it as i need, so frustrating.
On line 28 you update sum when you should be updating sum1, I think. If you wan the sum of each row you will have to reset sum1 before you start on a new row.

The problem description asks for the median and not the sum.
right but before i can get to median i need sum of all positive numbers no?
Line 1 should be:
`#include <iostream> `

You need:
`using namespace std;`

Line 7 should be:
`srand (time(NULL));`
time() requires #include <ctime>
http://www.cplusplus.com/reference/cstdlib/srand/

Line 17 should be:
`a[i][j]=(rand()%11)-5;`

Line 28 - You have an extraneous close brace.

Note that median is not necessary the same as the average. I don't think the sum will help you find the median.
Last edited on
Topic archived. No new replies allowed.