Đang tải... (xem toàn văn)
Lý thuyết và bài tập Pascal
{Bai 3.9} program B3_9; uses crt; var i, n: integer; 's: longint; begin clrscr, 'write(Nhap so n:'); readIn(n); 'writeln(n, ' phan tu dau tien cua tap A:'); s:=0; for Ì := 1ton begin sis2*s+1; 'writeln(So thu ', i, "', S); end; readin; end {Bai 3.10} program p3_10; uses crt; const max = 100; var a, duong, am, nguyento, hopso: array [1 max] of integer; i,j k, m,n, p, q: integer; ngto: boolean; begin €lrscr; {nhap n so} 'Write(Nhap so n:); readin(n); fori:=1tondo 91 begin write('So thu ', ¡ readlIn(a[i); end; {dem} m:=0; { so so duong} 0; { so so am} 0; { so so nguyen to } { so hop so} fori: 1tondo begin if ali] < then { so am } begin k;=k+1; amfk] := ali; end; if afi] > then begin m:=m+*1; duong[m] := ngto := true; Li]: forj := to trunc(sqrt(a[i])) if ali] modj = then { hop so} begin ngto := false; q:=q*1; hopso[q] := a[i]; break; end; if (ngto) and (a[i] > 1) then { nguyen to } begin p:=p+1; nguyento[p] := afi]; end; end; end; 92 {viet ket qua } { so duong } ifm> 0then begin 'writeln('Co ', m, ' so duong); forï := tom writeln('So duong thụ i, ": ', duong[i]); end else writeln('Khong co so duong nao’); {soam} ifk > then begin 'writeln(Co ', k, ' so am); for i:= † to k _writeln('So am thu ', i r1 ami]); end else 'writeln(Khong co so am nao’); { so nguyen to } ifp > then begin 'writeln('Co ', p, ' so nguyen to); fori:=1topdo 'writeln('So nguyen to thu ', í, ': ', nguyento[i]); end else writein(‘Khong co so nguyen to nao’); {hop so} ifq> then | begin 'writeln(Co ', q, ' hop so’); for ¡ := to q writeln(‘Hop so thu ', end „ hopso[i]); else 93 writein(Khong co hop so nao’); readin; end {Bai 3.11} uses cit; const nmax = 32000, type mang = array [1 nmax] of Integer, var ni: integer; a:mang; ketthuc : boolean; {: text, Procedure inketqua(k:integer); var j: integer, begin for j:=1 to k write(f,alj}:5); writeln(f); end; Procedure sinhmoi(K:integer); thu tu lon hon {Xay dung mot tong khac co tang dan} thoa man : cac so hang cua tong var j,i,tg : integer, begin i while (aJ]0) or (a[j-1]+2 > a[j]) dec(); ifj< then begin ketthuc:=true;exit end; a[j]=aU}-1: alj-1]=all-1]+1; ifjn) or (k0) : '); until n > 0; assign(f,'Ketqua txt); rewrite(f); for i:= n downto phantich(i,n); {phantich(4,19);} close(f); write(Ket qua file Ketqua.txt, an Enter de thoat."); readin; End (Bai 3.12} program p3_12; uses crt, const mang: array[1 5] of real = (1.0, op :array[1 4] of char var i 0, 4.0, 5.0, 6.0); = (+" : integer, a,b,c, n,t d: integer, :real, dien begin :boolean, clrser, write(Nhap so n:'); readin(n); dien := false; 1to4do forb:= for c:= 11o4 to to4do case a of :t;= mang[1] + mang[2]; mang[1] - mang[2], := mang[1] “ mang[2], end; case b of + mang[3]: ~ mang[3]; * mang[3]: = end; case c Of 96 t/ mang[3]: " _ + mang[4], 4:t:=t/ end; case d of - mang[4]; * mang[4]; mang[4];, 1:t:=t + mang[5]; 2: †- mang[5]; 3: t:=t* mang[5]; 4: †/ mang[5]; end; ifn=tthen begin dien := true; writeln(n = ', '(((1' op[a], '2}, op[b], 4), op[c] '5)', op[d], '6); end; end; if not dien then writeln(‘Khong the dien’); readin; end {Bai 3.13} uses crt; const nmax = 50; type var ma_tran = array [1 nmax, nmax] of integer; a,b : ma_tran; n,i,j : byte; Procedure Nhap_mt(var a : ma_tran;var n : byte); var i,j : byte; x,y : integer; begin _ fepeat 7-BTLT 97 clrscr, 'write(nhap so phan tu cua ma tran (n*(n-1) then begin if not f3 then begin writeln('Doi co so tran thang nhieu hon nua so tran dau: f3:=true; end; writeln(‘doi',i:4,".'); end; end; if not f3 then 101 writeln(‘Khong co doi nao thang nhieu hon nua tong so tran dau., readin, End {Bai 3.15} program p3_15; uses crt; const max = 20; var n, m, i, j: integer; 1, 12, t: integer; : array[1 max] of integer;, a,b _ begin €lrscr; { nhap n so} 'write(Nhap so n:); readin(n); fori:=1tondo begin write(So thu ', i, ` readIn(a[i]); end; {xoa cac so 0} b:= a; { luu mang a} m:=n; while i 12 then begin t=l1; 108 end; while i = 11) and (b[i]