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.
#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.
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?
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.