qfedu-cpp-level/day2/d3.cpp

23 lines
411 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
using namespace std;
// 引用传递: 会改变实参的值
// 值传递: 不会改变实参的值
void cumsum(int &total, int n) // total 是引用传递n 是值传递
{
total += n;
}
int main()
{
int total = 0;
int n = 0;
while (cin >> n)
{
cumsum(total, n);
cout << "total = " << total << endl;
if (total > 100)
break;
}
}