Bài 14. Nhập số nguyên dương n. Đếm số cặp (a, b) đôi một khác nhau sao cho a + b = n. Ví dụ:
CAPSO.INP |
CAPSO.OUT |
10 |
1 9 2 8 3 7 4 6 |
Code tham khảo:
#include <iostream>
using namespace std;
int main() {
freopen("CAPSO.INP","r",stdin);
freopen("CAPSO.OUT","w",stdout);
int n;
cin >> n;
for (int i = 1; i < n-1; i++) {
for (int j = i+1; j < n; j++) {
if (i + j == n)
cout << i << " " << j << endl;
}
}
return 0;
}