+ 1
Please explain this program.....
3 Answers
+ 3
#include <iostream> // including input and output library
using namespace std; // including std namespace
int main()
{
int num = 1;
int number;
int total = 0;
while (num <= 5) { // will be repeated 5 times, because the num variable gets increased every iteration
cin >> number; // input number
total += number; // add the number to the total variable
num++; // increase the num variable
}
cout << total << endl; // output total
return 0; // end of main function.
}
Basically this code finds sum of 5 numbers you enter.
+ 1
Alphin K Sajan,
You're wrong. Not number multiplied by 5, but sum of 5 numbers you enter.
Input:
1
2
3
4
5
Output:
15.
+ 1
This code gets 5 integer inputs from user and give sum of them.