Một tệp văn bản có tên KTHKII. TXT chứa đúng 2 dòng, dòng thứ nhất chứa số tự nhiên m, dòng thứ 2 chứa số tự nhiên n. Hãy viết chương trình đọc dữ liệu từ tệp trên, tính tổng và ghi kết quả vào tệp KQ. TXT

2 câu trả lời

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    int a,b;
    ifstream fileInput("KTHKII.TXT");
    ofstream fileOutput("KQ.TXT");
    fileInput>>a>>b;
    fileInput.close();
    fileOutput<<a+b;
    fileOutput.close();
    //samon247
    return 0;
}

uses crt;
var m,n: integer;
begin
assign(input,'KTHKII.TXT');
assign(output,'KQ.TXT');
reset(input); rewrite(output);
readln(input,m,n);
close(input);
write(output,m+n);
close(output);
readln
end.

Câu hỏi trong lớp Xem thêm
2 lượt xem
2 đáp án
8 giờ trước