cho tệp toado. inp gồm nhiều dòng mỗi dòng là 2 số nguyên a, b tương ứng là tọa độ của 1 điểm. Tính khoảng cách của điểm có tọa độ (a, b) với điểm có tọa độ (0,0) kết quả ghi vào tệp kqua. out ( mn giúp e vs ạ)

2 câu trả lời

$\color{red}{\text{Pascal:}}$
const fi='toado.inp';

         fo='toado.out';

var a,b:real;

begin

assign(input,fi);

reset(input);

assign(output,fo);

rewrite(output);

while not eof(f) do

begin

read(a,b);

writeln(trunc(sqrt(a*a+b*b)));

end;

close(input);

close(output);

end.

$\color{red}{\text{C++:}}$

#include <bits/stdc++.h>

using namespace std;

int main(){
    freopen("toado.inp","r",stdin);
    freopen("toado.out","w",stdout);
    int a,b;
    while (cin>>a>>b){
        cout<<floor(sqrt(a*a+b*b))<<'\n';
    }
}

program bai_giai;
var f,g:text;
    a,b:integer;
begin
    Assign(f,'toado.inp');  reset(f);
    Assign(g,'kqua.out');  rewrite(g);
    while not eof(f) do
        begin
            readln(F,a,b);
            writeln(g,sqrt(sqr(a)*sqr(b)):0:2);
        end;
    close(f); close(g);
end.

Câu hỏi trong lớp Xem thêm