Can any one plzz explain this programm | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can any one plzz explain this programm

#include <iostream> using namespace std; int main() { int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl; return 0; }

11th Mar 2017, 5:49 AM
CH.Durga Prasanna Kumar
CH.Durga Prasanna Kumar - avatar
6 Answers
+ 3
hii ADITI! in this programme there will be a loop . which means the tge while loop will be executed until value of num becomes 5. then it will take input in integer number and will add it with the variable total and store the value of sum to variable total......after the loop will end it will show the last value of variable total.....its just simple....BEST WISHES
8th Jun 2017, 5:12 PM
Prateek Soni
Prateek Soni - avatar
+ 2
srry i haven't noticed that u hsve answered it....i think u posted this question
10th Jun 2017, 11:28 AM
Prateek Soni
Prateek Soni - avatar
+ 1
this program gets 5 numbers from user, calculate thier sum then print it
11th Mar 2017, 5:53 AM
ahmad
ahmad - avatar
+ 1
When you input 2, you gave 5 inputs all equal to 2. Thus, at the time of first execution of while loop, num=1, total=2 and the number became 2 as you inputted. While loop will run 5 times till the value of num is equal to 5 and therefore, the value of total after subsequent addition comes out 10. 10 is the output, hence.
11th Mar 2017, 11:08 AM
Aditi Thakur
Aditi Thakur - avatar
0
if i enter 2 out put will b 10 ..can u plz explain
11th Mar 2017, 5:55 AM
CH.Durga Prasanna Kumar
CH.Durga Prasanna Kumar - avatar
0
Have explained the same @Prateek
8th Jun 2017, 5:16 PM
Aditi Thakur
Aditi Thakur - avatar