qfedu-basic-level/day9/d3.cpp

30 lines
550 B
C++
Raw Permalink 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.

// 有效循环n次则addNums调用n次每一次调用都会入栈创建栈帧
#include <iostream>
using namespace std;
int addNums(int a, int b); // 函数的声明
int main()
{
int x, y;
while (1)
{
cout << "请输入两个整数:";
cin >> x;
if (x == 0)
break;
cin >> y;
// 调用函数
int ret = addNums(x, y);
cout << "计算结果为:" << ret << endl;
}
return 0;
}
// 函数的定义
int addNums(int a, int b)
{
return a + b;
}