Massive row HELP - Determining arithmetic mean in a row

Hi, i have trouble finding a way to determine arithmetic mean in each row.
The task asks me to get all the POSITIVE numbers in each row and determing the arithmetic mean.

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
int main ()
{
randomize();
int a[20][20], n, m;
int i,j,sum=0, sum1=0;
   cout<<"Input amount of rows n ";
   cin>>n;
   cout<<"Input amont of columns m ";
   cin>>m;

   for(i=0; i<n; i++){
   	for(j=0; j<n; j++){
      a[i][j]=random(11)-5;
      cout<<a[i][j]<<" ";

      }
      cout<<"\n";
      }
      for(i=0; i<m; i++){
    sum1=0;
      for(j=0; j<n; j++){
                sum1=sum1+a[i][j];  }cout<<i+1<<". Row total: "<<sum1<<"\n";}
                     

      getch();
   }


The task asked me to make a masive with random numbers from -5 to 5 which i did but as you can see have no clue how to actually get that arithmetic mean.

Any help appreciated
bump have some time for this but still struggling anyone?

How can i get the arithmetic mean from all the positive numbers in each row.
Last edited on
How would you do it on paper? If I gave you a list of numbers and asked you to tell me the average value of all the positive numbers in the list.
id just get all the positive numbers out of each row and then get them in the correct order, but i cant quite do that in here since i cant pick each one out. Or at elast i think so
Break it down further. How are you getting all the positive numbers? It sounds silly but this is programming. All that stuff about syntax is just learning the notation. Programming is the art and craft of thinking about problems in a way that the solution lends itself to a programmatical implementation. This is a very simple problem and just telling you what to do won't help you at all.

Why do you want to put them into an order. I didn't ask you to put them in order. I asked you to give me the average value of them.

Here are some numbers:

2 -4 5 -6 -3 3

What's the average value of the positive numbers? Watch yourself answering the question. How did you do it?
2+5+3/3=3,333

obviously but how do i do get sum from all the positive numbers in a row and then can divide by the amount of numbers there were?
Last edited on
So you LOOKED at each number.
You DECIDED if the number was positive or not.
IF it was positive, you ADDED it to the total.
When you had read all the numbers in the row, you then divided the total by the number of positive values you found.

Now turn each step into code.
oh i think i got it

thanks!
Topic archived. No new replies allowed.