0
Can u solve this?Take 5 values as input and find the average
https://code.sololearn.com/cULtlxwyH5Eq/?ref=app i found the avrage...but why the ans is wrong??the ans should be 6!
8 odpowiedzi
+ 1
Good Gamer Rayeed, actually, your average is coming as 6. The only problem here is that 6 is being printed in the same line right after the sum, which is 30, causing it to appear as 306.
When printing your average, try:
cout<<"\n"<<avg;
The "\n" here is an escape sequence which essentially creates a new line. Try it now, the average should be printed in the next line.
+ 2
Good Gamer Rayeed, since you have already found the sum, the only thing left for you to do to get the average is divide the sum by the no. of observations or inputs (in your case, 5).
To get that, you could do:
int avg=sum/5;
cout<<avg;
If you had 7 inputs, you would go like:
int avg=sum/7;
cout<<avg;
+ 1
Run this code, and uncomment each cout line to see the difference in output produced by using different escape sequences.
https://code.sololearn.com/cG567nDob4Ur/?ref=app
Here I've only shown you 2 (common) escape sequences. For a list of other escape sequences, check out this link: https://en.cppreference.com/w/cpp/language/escape
0
mean=no of observations/total no of observations
0
tnx..i know how to do but i didn't know the average procesure in coding..
0
i found the aveg but its coming 300 something, the ans should be 6!!
plz help me
https://code.sololearn.com/cULtlxwyH5Eq/?ref=app
0
tnx..i will be glad to u!!🇧🇩😊
0
how can I give the output - average 6
https://code.sololearn.com/cULtlxwyH5Eq/?ref=app