Viết chương trình đọc 3 số nguyên dương a,b,c từ tệp C:\input.txt a) Tính tổng 3 số và ghi ra tệp C:\output.txt b) Tính tích 3 số và ghi ra tệp C:\output.txt c) Tìm số lớn nhất trong 3 số và ghi ra tệp C:\output.txt C:\input. C:\output 2,3,6. 11 ,36 ,6

2 câu trả lời

uses crt;
const fi='dayso.txt';
fa='tong.txt';
fb='kq.txt';
var f1,f2,f3:text;
a:array[1..100]of integer;
n,i,t,kt,j:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
assign(f2,fa); rewrite(f2);
assign(f3,fb); rewrite(f3);
n:=0;
while not eof(f1) do
begin
n:=n+1;
readln(f1,a[n]);
end;
{--------------------------cau-a--------------------------}
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(f2,'tong cua day so la: ',t);
{--------------------------cau-b--------------------------}
writeln(f3,'cac so chan trong day la: ');
for i:=1 to n do
if a[i] mod 2=0 then write(f3,a[i]:4);
writeln(f3);
writeln(f3,'cac so le trong day la: ');
for i:=1 to n do
if a[i] mod 2<>0 then write(f3,a[i]:4);
{--------------------------cau-c--------------------------}
writeln('cac so nguyen to trong day la: ');
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to a[i]-1 do
if a[i] mod j=0 then kt:=1;
if kt=0 then write(a[i]:4);
end;
close(f1);
close(f2);
close(f3);
readln;
end.

program bai_giai;
var f,g:text;
    a,b,c,max:integer;
begin
    Assign(f,'C:\input.txt');  reset(f);
    Assign(g,'C:\ouput.txt');  rewrite(g);
    readln(f,a,b,c);
    max:=a;
    if b>max then max:=b;
    if c>max then max:=c;
    write(g,a+b+c,' ',a*b*c,' ',max);
    close(f); close(g);
end.