Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 20 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
20
Dung lượng
52,5 KB
Nội dung
{ Program PhuongTrinhbac2; Var a,b,c,delta,x1,x2,xk: real; BEGIN Writeln('Chuong trinh giai PT bac hai:'); Writeln('Hay nhap cac he so:'); Write('a = '); readln(a); Write('b = '); readln(b); Write('c = '); readln(c); Delta:=b*b-4*a*c; If Delta > 0 then Begin x1:=(-b+Sqrt(Delta))/(2*a); x2:=(-b-Sqrt(Delta))/(2*a); Writeln('Phuong trinh co hai nghiem phan biet:'); Writeln('x1 = ',x1:5:2); Writeln('x2 = ',x2:5:2); End Else If Delta = 0 then Begin xk:=-b/(2*a); Writeln('PT co mot nghiem kep xk = ',xk:5:2); End Else Writeln('Phuong trinh vo nghiem .'); Readln END. Program Max3; Var a,b,c,max: Integer; BEGIN Writeln('Tim so lon nhat cua 3 so:'); Write('Nhap vao ba so a, b, c = ');Readln(a,b,c); max:= a; If max < b then max:= b; If max < c then max:= c; Writeln('So lon nhat la: ',max); Readln END. Program ThangQuy; Var thang,quy:1 12; BEGIN Writeln('Chuong trinh kiem tra xem mot thang thuoc quy nao.'); Write('Nhap vao thang can kiem tra: '); Readln(thang); If thang mod 3 = 0 then quy:= thang div 3 Else quy:= thang div 3 + 1; Writeln('Thang ',thang,' thuoc quy ',quy); Readln END. Program KiemTraTamGiac; Var a,b,c: Word; BEGIN Writeln('Kiem tra xem mot tam giac Nhon, Tu hay Vuong:'); Writeln('Nhap vao ba canh cua tam giac (a, b, c > 0) .'); Write('a, b, c = '); Readln(a,b,c); IF ((a+b)>c) And ((a+c)>b) And ((b+c)>a) then Begin IF (a>=b) And (a>=c) then Begin If a*a > b*b + c*c then Writeln('Day la tam giac Tu .'); If a*a = b*b + c*c then Writeln('Day la tam giac Vuong .'); If a*a < b*b + c*c then Writeln('Day la tam giac Nhon .'); End; IF (b>=a) And (b>=c) then Begin If b*b > a*a + c*c then Writeln('Day la tam giac Tu .'); If b*b = a*a + c*c then Writeln('Day la tam giac Vuong .'); If b*b < a*a + c*c then Writeln('Day la tam giac Nhon .'); End; IF (c>=a) And (c>=b) then Begin If c*c > a*a + b*b then Writeln('Day la tam giac Tu .'); If c*c = a*a + b*b then Writeln('Day la tam giac Vuong .'); If c*c < a*a + b*b then Writeln('Day la tam giac Nhon .'); End; End Else Writeln('Khong la ba canh cua tam giac .'); Readln END. Program GiaiHePT; Var a1,b1,c1,a2,b2,c2: Integer; Delta,deltax,deltay,x,y: Real; BEGIN Writeln('Giai he hai PT bac nhat hai an.'); Write('Nhap cac he so a1, b1, c1 = '); Readln(a1,b1,c1); Write('Nhap cac he so a2, b2, c2 = '); Readln(a2,b2,c2); Delta:=a1*b2-a2*b1; Deltax:=c1*b2-c2*b1; Deltay:=a1*c2-a2*c1; IF Delta = 0 then Begin If Deltax <> Deltay then Writeln('He PT vo nghiem .') Else Writeln('He PT co vo so nghiem dang: x, y=(',c1,'-',a1,'x)/',b1) End Else IF Deltax=Deltay then Writeln('He PT co vo so nghiem dang: x, y=(',c1,'-',a1,'x)/',b1) ELse Begin x:=Deltax/Delta; y:=Deltay/Delta; Writeln('He PT co nghiem x = ',x:0:2,', y = ',y:0:2); End; Readln END. Program TinhTong; Var S,i,n: Word; BEGIN Writeln('Tinh tong cua n so tu nhien.'); Write('Nhap so tu nhien n = '); Readln(n); S:= 0; For i:= 1 to n do S:= S + i; Writeln('Ket qua la: S = ',S); Readln END. Program TinhTongBinhPhuong; Var S,i,n: Word; BEGIN Writeln('Tinh tong binh phuong cua n so tu nhien.'); Write('Nhap so tu nhien n = '); Readln(n); S:= 0; For i:= 1 to n do S:= S + i*i; Writeln('Ket qua la: S = ',S); Readln END. Program TinhTongPhanSo; Var S: Real; i,n: Word; BEGIN Writeln('Tinh tong 1/n cua n phan so.'); Write('Nhap so tu nhien n = '); Readln(n); S:= 0; For i:= 1 to n do S:= S + 1/i; Writeln('Ket qua la: S = ',S:10:2); Readln END. Program TinhGiaiThua; Var i,n: Word; P: Real; BEGIN Writeln('Tinh giai thua cua so n>=0.'); Write('Nhap vao so n = '); Readln(n); IF n>0 then Begin P:= 1; For i:=1 to n do P:=P*i End Else If n=0 then Readl END. Program TinhCanThuc; Var i,n:Word; S:Real; BEGIN Writeln('Tinh tong can thuc.'); Write('Nhap so n = '); Readln(n); S:= n; For i:=n-1 Downto 0 do S:= i + Sqrt(S); Writeln('Ket qua S = ',S:10:3); Readln END. Program TinhTongPhanSo; Var i,n:Word; S:Real; BEGIN Writeln('Tinh tong Phan so.'); Write('Nhap so n = '); Readln(n); S:= n; For i:=n-1 Downto 0 do S:= i + 1/S; Writeln('Ket qua S = ',S:10:3); Readln END. Program TimUCLN; Var a,b: Integer; BEGIN Writeln('Tim UCLN cua hai so khac 0.'); Write('Nhap hai so a, b = '); Readln(a,b); a:=ABS(a); b:=ABS(b); While a<>b do If a>b then a:=a-b Else b:=b-a; Writeln('Ket qua UCLN cua hai so la: ',a); Readln END. Program BanCuuChuong; Var i,j: Byte; BEGIN Writeln('BAN CUU CHUONG:'); For i:=2 to 9 do For J:= 1 to 10 do Writeln(i,'x',j,' = ',i*j); Readln END. Program BanCuuChuong; Var i,j: Byte; BEGIN Writeln('BAN CUU CHUONG:'); For j:=1 to 10 do Begin For i:= 1 to 5 do Write(i,'x',j:2,'=',i*j:2,' ');Writeln; End; Writeln; For j:=1 to 10 do Begin For i:= 6 to 10 do Write(i,'x',j:2,'=',i*j:2,' ');Writeln; End; Readln END. Program BaiToanGaCho; Var sg,sc: Byte; BEGIN Writeln('Bai toan co Ga + Cho = 36 con. Chan ga + Chan Cho = 100 chan'); For sg:=1 to 36 do For sc:=1 to 25 do If (sg*2+sc*4=100) And (sg+sc=36) then Writeln('Ket qua So Ga la: ',sg,' So Cho la: ',sc); Readln END. Program BaiToanTramTrauTramCo; Var td,tn,tg: Byte; BEGIN Writeln('Co 100 Trau an 100 bo co.'); Writeln('Trau dung an 5, Trau nam an 3, Trau gia 3 con/1bo.'); Writeln('CAC KET QUA LA:'); For td:=1 to 20 do For tn:=1 to 33 do For tg:=1 to 100 do If (td*5+tn*3+tg/3=100) And (td+tn+tg=100) then Begin Writeln('Trau dung co: ',td,' con'); Writeln('Trau nam co: ',tn,' con'); Writeln('Trau gia co: ',tg,' con'); Writeln; End; Readln END. Program TinhTongChuSo; Var n: LongInt; tong: Byte; BEGIN Writeln('Tinh tong cac chu so cua STN n.'); Write('Nhap STN n = '); Readln(n); Write('Tong cac chu so cua ',n,' la: '); tong:= 0; Repeat tong:=tong + n mod 10; n:= n div 10; Until n = 0; Writeln(tong); Readln END. Program KiemTraSNTo; Var i,j,n: Integer; Dung: Boolean; BEGIN Writeln('Kiem tra xem n co la So Nguyen To hay khong?'); Write('Nhap So Nguyen n = '); Readln(n); Dung:= False; IF (n=2) Or (n= 3) then Dung:=True; IF n>3 then Begin i:=2; j:=n div 2; While (i<=j) And (n mod i <> 0) do i:=i+1; If i > j then Dung:= true; End; If Dung then Writeln('Ket qua ',n,' co la So Nguyen To.') Else Writeln('Ket qua ',n,' khong la So Nguyen To.'); Readln END. Program TinhTongCacUoc; Var tong,n,i: integer; BEGIN Writeln('Chuong trinh tinh tong cac uoc thuc su cua mot so:'); Write('Nhap so n = '); Readln(n); tong:=0; For i:=2 to (n div 2) do If n mod i = 0 then tong:= tong+i; Writeln('Tong cac uoc thuc su cua ',n,' la: ',tong); Readln END. Program SoHoanHao; Var Tonguoc,i,n: Integer; BEGIN Writeln('Kiem tra xem mot so cola So Hoan Hao khong?'); Write('Nhap so n = '); Readln(n); Tonguoc:= 0; For i:= 1 to (n div 2) do If (n mod i = 0) then Tonguoc:=Tonguoc + i; If Tonguoc = n then Writeln('So ',n,' la So Hoan Hao') Else Writeln('So ',n,' Khong la So Hoan Hao'); Readln END. Program TimCacSoHoanHao; Var Tonguoc,i,j,n: Integer; BEGIN Writeln('Kiem tra xem co bao nhieu so la So Hoan Hao?'); Writeln('Tim kiem tu 1 den MaxInt .'); Writeln('Chuong trinh thuc hien trong may phut, Xin cho '); Writeln('Cac so Hoan Hao la:'); n:= MaxInt; For j:=2 to n do Begin Tonguoc:= 0; For i:= 1 to (j div 2) do If (j mod i = 0) then Tonguoc:=Tonguoc + i; If Tonguoc = j then Writeln(j); ENd; Writeln('Ket thuc .'); Readln END. Program TimKiemTheoMau; Var M: Array[1 100] of Integer; i,n: 1 100; x: Integer; Thay: Boolean; BEGIN Writeln('Chuong trinh tim xem x co thuoc day so nguyen hay khong?'); Write('Nhap day so, co so phan tu (n<= 100).Nhap n = '); Readln(n); For i:= 1 to n do Begin Write('Phan tu thu ',i,' = '); Readln(M[i]); End; Write('So can tim x = '); Readln(x); i:=1; Thay:= False; While (i<=n) And (not Thay) do If x = M[i] then Thay:= true Else i:=i+1; If thay then Writeln('So ',x,' tim thay tai vi tri ',i) Else Writeln('Khong co ',x,' trong day .'); Readln END. Program TimKiemTheoMau; Var M: Array[1 100] of Integer; i,n: 1 100; x: Integer; Thay: Boolean; BEGIN Writeln('Chuong trinh tim xem x co thuoc day so nguyen hay khong?'); Write('Nhap day so, co so phan tu (n<= 100).Nhap n = '); Readln(n); For i:= 1 to n do Begin Write('Phan tu thu ',i,' = '); Readln(M[i]); End; Write('So can tim x = '); Readln(x); Write('So ',x,' tim thay tai cac vi tri la:'); Thay:= False; For i:=1 to n do If x = M[i] then Begin Thay:= true; Write(i:3); End; If not thay then Writeln('Khong co ',x,' trong day .'); Readln END. Program TimKiemMaxMin; Var M: Array[1 100] of Integer; i,n: 1 100; vtmax,vtmin: Byte; BEGIN Writeln('Chuong trinh tim Min, Max cua day so nguyen?');