Bài toán. Đọc số nguyên dương n và dãy số a1, a2, …. an từ file DAYSO.INP. Ghi lại vào file DAYSO.OUT. Dòng thứ nhất ghi n, dòng thứ hai ghi dãy số, mỗi phần tử cách nhau một dấu cách. Ví dụ:
DAYSO.INP |
DAYSO.OUT |
6 11 21 15 17 13 19 |
6 11 21 15 17 13 19 |
Code tham khảo:
#include <iostream>
using namespace std;
int main () {
freopen("DAYSO.INP","r",stdin);
freopen("DAYSO.OUT","w",stdout);
int n, a[1000];
cin >> n;
// Doc day so:
for (int i = 0; i < n; i++) {
cin >> a[i];
}
// Ghi day so:
cout << n << endl;
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
return 0;
}