23 lines
411 B
C++
23 lines
411 B
C++
#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;
|
||
}
|
||
} |