qfedu-basic-level/day7/d3.cpp

21 lines
429 B
C++
Raw Normal View History

2023-06-21 14:30:56 +08:00
// 测试多分支结构
#include <iostream>
#include <cmath> // c++ 数学库: 提供 abs() 函数
using namespace std;
int main()
{
cout << "请输入2个数: ";
int a, b;
cin >> a >> b;
if (a >= 0 && b >= 0)
cout << "a + b = " << a + b << endl;
else if (a < 0 && b < 0)
cout << "a * b = " << a * b << endl;
else
{
cout << "a 和 b 差值: " << abs(a - b) << endl;
}
}