A30811.计算(a+b)/c
2025-09-07 07:13:25
发布于:江苏
0阅读
0回复
0点赞
练习一下try
,throw
,catch
的用法,虽然不方便,但是考试会考。
#include <iostream>
using namespace std;
int divide_s(const int &a, const int &b) {
if (b == 0) throw "error";
return a/b;
}
int main() {
long long a, b, c;
cin >> a >> b >> c;
try{
cout << divide_s(a+b, c);
}catch(const char* err) {
cout << "no";
}
return 0;
}
这里空空如也
有帮助,赞一个