现输入一个正整数 N(1≤N≤100),代表接下来有N行每行有三个正整数 a , b , c。
3条回答 默认 最新
关注引自免费微信小程序:皆我百晓生
好的,我已经了解您的需求,以下是您所需的C++程序。
#include<iostream> using namespace std; int main(){ int N; cin >> N; for(int i = 1; i <= N; i++){ int a, b, c; cin >> a >> b >> c; if(a + b == c){ cout << "The sum of the three numbers is " << a + b << endl; } else { cout << "There is an error in the numbers." << endl; } } return 0; }在这个程序中,我们首先通过cin从用户那里获取一个正整数N。然后,我们遍历所有可能的三元组(a、b和c),并检查它们是否满足条件:a + b等于c。如果是,则输出总和。如果不是,则输出错误消息。这样,无论输入的是多少个数,程序都会返回正确的结果。
解决 无用评论 打赏 举报 编辑记录