PROGRAM BT7_40;
USES crt;
VAR n,m,i,j,k,s : INTEGER;
A:ARRAY[1..100,1..100] OF INTEGER;
BEGIN
clrscr;
s:=0;
k:=0;
Write('Nhap m,n : ') ;
Readln(m,n);
FOR i:= 1 TO n DO
FOR j:= 1 TO m DO
BEGIN
Writeln('Nhap A[',i,',',j,'] : ');
Readln(A[i,j]);
END;
writeln;
writeln;
FOR i:=1 TO n DO
FOR j:= 1 TO m DO
IF A[i,j] MOD (i+j) =0 THEN BEGIN k:=k+1; s:=s+A[i,j]; END;
Writeln('Ma tran A : ');
writeln;
FOR i :=1 TO n DO
BEGIN
FOR j := 1 TO m DO
write(A[i,j]:5);
Writeln;
writeln;
END;
Writeln('Tong la : ',s);
Writeln('So luong : ',k);
readln;
END.
---------------------------------
PROGRAM BT7_41;
USES crt;
VAR n,m,k,i,j,s,l: INTEGER;
A:ARRAY[1..100,1..100] OF INTEGER;
BEGIN
clrscr;
s:=0;
l:=0;
Write('Moi nhap m, n : ');
Readln(m,n);
FOR i:=1 TO n DO
FOR j:=1 TO m DO
BEGIN
Writeln('Moi nhap A[',i,',',j,'] : ');
Readln(A[i,j]);
END;
Writeln('Ma tran A la : ');
Writeln;
FOR i:= 1 TO n DO
BEGIN
FOR j:=1 TO m DO
Write(A[i,j]:4);
writeln;
Writeln;
END;
FOR j:= 1 TO m DO
s:=s+A[1,j];
Writeln('Tong cac phan tu dong 1 la : ',s);
Readln;
Writeln('Moi nhap k: ');
Readln(k);
FOR i:=1 TO m DO
l:=l+ A[i,k];
Writeln('Tong cac phan tu cot ',k,' la : ',l);
Readln;
END.
------------------------------------
PROGRAM BT7_42;
USES crt;
VAR n,m,i,j,k,t : INTEGER;
A:ARRAY[1..100,1..100] OF INTEGER;
BEGIN
clrscr;
Write('Moi nhap m, n : ');
Readln(m,n);
FOR i:=1 TO n DO
FOR j:=1 TO m DO
BEGIN
Writeln('Moi nhap A[',i,',',j,'] : ');
Readln(A[i,j]);
END;
Writeln('Ma tran A la : ');
Writeln;
FOR i :=1 TO n DO
BEGIN
FOR j:= 1 TO m DO
Write(A[i,j]:4);
Writeln;
Writeln;
END;
FOR k:= n DOWNTO 2 DO
FOR i:=1 TO n-1 DO
IF A[i,1] > A[i+1,1] THEN
BEGIN
t:=A[i,1];
A[i,1]:=A[i+1,1];
A[i+1,1]:=t;
END;
Writeln('Ma tran sau khi da sap xep : ');
FOR i:=1 TO n DO
BEGIN
FOR j:=1 TO m DO
Write(A[i,j]:4);
Writeln;
Writeln;
END;
readln;
END.
---------------------------------------
Program Chuyen;
uses crt;
Var S:string;
N,i,k,h:integer;
Begin
write('Nhap vao so N:');
Readln(N);
S:='';
while N <>0 do
Begin k:=N mod 2; if k=0 then S:='0'+S else S:='1'+S; N:=N div 2; End;
write(S);
Readln
End.
------------------------
Program npsangtp;
uses crt;
Var S:string;
A:array[1..100] of integer;
N,i,k,gt:integer;
Begin
write('Nhap vao so nhi phan : ');
Readln(S);
For i:=1 to length(s) do
if S[i]='1' then A[i]:=1
else
A[i]:=0;
N:=0;
For i:=1 to length(S) do
Begin
gt:=1;
For k:=1 to length(S)-i do
gt:=gt*2;
N:=N+A[i]*gt;
End;
write('So thap phan la:',N);
Readln
End.