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; }
6 odpowiedzi
+ 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
+ 2
srry i haven't noticed that u hsve answered it....i think u posted this question
+ 1
this program gets 5 numbers from user, calculate thier sum then print it
+ 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.
0
if i enter 2 out put will b 10 ..can u plz explain
0
Have explained the same @Prateek