[r]
(1)(2)Bài 1: Chương trình Pascal VAR
i, n: INTEGER; x, p, S: REAL; BEGIN
Write('x, n = '); Readln(x, n); S := 1; p := 1;
FOR i := TO n DO BEGIN
p := p * x / i; S := S + p; END;
Writeln('exp(', x:1:4, ') = ', S:1:4); readln;
END.
Bài 2: Chương trình Pascal USES crt;
VAR n: LONGINT; m,tong,i: INTEGER; BEGIN
clrscr;
write('Nhap n: '); readln(n); write('Nhap m: '); readln(m); tong:=0;
FOR i:=1 TO m DO BEGIN
tong:=tong+(n MOD 10); n:=n DIV 10;
END;
write('Tong ',m,' chu so cuoi cua so vua nhap = ',tong); readln;
END.
Bài 3: Chương trình Pascal VAR tep1,tep2:TEXT;
i,n,s:INTEGER;
a:ARRAY[1 100] OF INTEGER; BEGIN
assign(tep1,'D:\BT.txt'); rewrite(tep1);
write('nhap n= ');readln(n); FOR i:=1 TO n DO
BEGIN
(3)write(tep1,a[i]:4); END; close(tep1); assign(tep2,'D:\BT1.txt'); rewrite(tep2); reset(tep1); s:=0;
WHILE NOT eof(tep1) DO BEGIN
read(tep1,a[i]); write(a[i]:4);
IF(a[i] MOD 2=0) THEN s:=s+a[i]; END;
write(tep2,s); writeln;
write('Tong cac so chan co day la: ',s); close(tep2);
readln; END.
Bài 4: Chương trình Pascal USES Crt;
TYPE Mang = ARRAY[1 10,1 10] OF INTEGER; VAR A:Mang;
m,n,i,j,x,dem,S,max:INTEGER; BEGIN
Write('Nhap so dong m='); Readln(m); Write('Nhap so cot n='); Readln(n); FOR i:=1 TO m DO
FOR j:=1 TO n DO BEGIN
Write('A[',i,',',j,']='); Readln(A[i,j]); END;
FOR i:=1 TO m DO BEGIN
FOR j:=1 TO n DO Write(A[i,j]:5); Writeln;
END;
Write('Nhap x='); Readln(x); dem:=0;
Writeln('Vi tri cua x mang A: '); FOR i:=1 TO m DO
(4)BEGIN
Write(i,',',j,' ; '); dem:=dem+1; END;
Writeln('So lan xuat hien cua x mang A la: ',dem); S:=0;
FOR i:=1 TO m DO BEGIN
Max:=A[i,1];
FOR j:=2 TO n DO
IF max<A[i,j] THEN max:=A[i,j]; S:=S+max;
END;
Writeln('Tong cac phan tu lon nhat cua moi dong la: ',S); Readln;