HOC24
Lớp học
Môn học
Chủ đề / Chương
Bài học
Bài 2:
program bt;uses crt;var i, n, s : integer;a : array[1..100] of integer;begin clrscr; write('Nhap so so nguyen: '); readln(n); for i:=1 to n do begin write('Nhap so thu ',i,': '); readln(a[i]); end; s := 0; write('Day so vua nhap la: '); for i:=1 to n do begin write(a[i],', '); s := s + a[i]; end; writeln; writeln('Tong cac so trong day so la ',s); writeln('Trung binh cong cac so trong day so la ',s/n:0:2); readlnend.
Bài 3:
program bt;uses crt;var i, n, s, d : integer;a : array[1..100] of integer;begin clrscr; write('Nhap so so nguyen: '); readln(n); for i:=1 to n do begin write('Nhap so thu ',i,': '); readln(a[i]); end; s := 0; d := 0; for i:=1 to n do if (a[i] > 10) and (a[i] < 20) then begin d := d + 1; s := s + a[i]; end; writeln('Co ',d,' so nho hon 10 va lon hon 20'); write('Tong cac so lon hon 10 va be hon 20 la ',s); readlnend.
program bt;uses crt;var i, max : integer;a : array[1..10] of integer;begin clrscr; for i:=1 to 10 do begin write('Nhap so thu ',i,': '); readln(a[i]); end; max := 0; for i:=1 to 10 do if a[i] > max then max := a[i]; if (max mod 2 = 0) then write(max,' la so lon nhat va la so chan') else write(max,' la so lon nhat va la so le'); readlnend.
hảo
program bt;uses crt;var i, s, sa, sd, sc, sl, da, dd, dc, dl : integer;a : array[1..50] of integer;begin clrscr; for i:=1 to 10 do begin write('Nhap phan tu thu ',i,': '); readln(a[i]); end; write('Day so vua nhap la: '); for i:=1 to 10 do write(a[i],', '); writeln; s := 0; sa := 0; sd := 0; sc := 0; sl := 0; da := 0; dd := 0; dc := 0; dl := 0; for i:=1 to 10 do begin s := s + a[i]; if (a[i] > 0) then begin sd := sd + a[i]; dd := dd + 1 end; if (a[i] < 0) then begin sa := sa + a[i]; da := da + 1 end; if (a[i] mod 2 = 0) then begin sc := sc + a[i]; dc := dc + 1; end else begin sl := sl + a[i]; dl := dl + 1 end; end; writeln('Tong cac phan tu trong mang la ',s); writeln('Trung binh cong cac phan tu trong mang la ',s/10); writeln('Tong cac so am la ',sa); writeln('Tong cac so duong la ',sd); writeln('Tong cac so chan la ',sc); writeln('Tong cac so le la ',sl); writeln('So cac so am la ', da); writeln('So cac so duong la ', dd); writeln('So cac so chan la ', dc); writeln('So cac so le la ', dl); readlnend.