+ 1

To find the average height of a group of students using for statement

12th Jun 2018, 3:29 PM
Beenu Thomas
4 Antworten
+ 6
Is this a homework. Make a for loop with two variables height and number. Declare how many times you have to take input as statement. each time add it to height and increment number. Declare a variable which will be height/number. For example, you have to take heights of five students.You can do it like this. int height, number. for(int i = 0; i < 5;i++ ){ int c; cin >> c; height += c; number++; } average = height/number; cout << average.
12th Jun 2018, 3:43 PM
Akash Pal
Akash Pal - avatar
+ 1
please give the answer as a program
12th Jun 2018, 3:47 PM
Beenu Thomas
+ 1
Beenu Thomas Have you tried it yourself.
12th Jun 2018, 3:59 PM
Akash Pal
Akash Pal - avatar
+ 1
Yes. I got the answer
12th Jun 2018, 4:01 PM
Beenu Thomas