PHAN II LỜI GIẢI, ĐÁP ÁN Chương 1 Sử dụng biểu thức câu lệnh {Bai 1.1 Bạn đọc tự làm} {Bai 1.2} Program Pascal; BEGIN writeLn(/PASCAL); writeLn/PASCAL":11); writeLn(PASCAL':16); writeLn(PASCAL':21); writeLn(/PASCAL':26); readin; END {Bai 1.3 Ban đọc tự trả lời} {Bai 1.4} Program Pascal; var a,b: real; BEGIN
'write(Nhap vao so a);readln(a);
Trang 2writeln(‘a / b = ‘,a/b); readin; END {Bai 1.5} Program mu_va_log; Var a,X,y,Z: real; BEGIN
write(Nhap vao so a (a>0,a<>1): ');readIn(a); write(Nhap vao so x (x>0): ');readIn(x); y := exp(x"In(a)); z:=In(x)/In(a), writeln(a^x = ',y); writeln(‘loga(x) = ',z); readin, END {Bai 1.6} Program Tinh_tien; var a1,a2,a3,a4,a5,a6: integer; BEGIN
write(Nhap vao so to 800.000: ');readin(a1);
write(Nhap vao so to 100.000: ');readln(a2); 'write(Nhap vao so to 50.000: ’);readin(a3); 'write(Nhap vao so to 5.000: ');readIn(a4);
write(Nhap vao so to 1.000: ');readIn(a6);
'write(Nhap vao so to 200: ');readIn(a6);
writeln('Tong so tien: ',500*a1+100*a2+50*a3+5*a4+a5+0.2*a6); readin;
END
Trang 3{Bai 1.7} Program Doi_gio; var t,h,m,s: integer; BEGIN write('(Nhap vao tong so giay: ');readin(t); h:= t div 3600; t=t mod 3600; m:= tdiv 60; t=t mod 60; sist; writeln(hh:mm:ss readin; END {Bai 1.8) Program Nhan_tay; var sh1,sh2,d1,d2,d3,kq; integer; BEGIN
'write(Nhap vao so thu nhat: ');readin(sh1);
Trang 4{Bai 1.9) Program Tien_gui_ngan_hang; var A,s: real; ¡t:integer; BEGIN
write(Nhap vao so von A (80 trieu): );readln(A); write(Nhap vao so thang t (24 thang): ');readin(t);
write(‘Nhap vao lai suat s (1 %): ');readin(s); A:= A*(1- exp(f'ln(s/100)) )/(1-s/100),
writeln(’Ca von va lai sau 't' thang la: ',A:25:3, trieu); readin; END {Bai 1.10} Program Tam_giac_ABC; vat X1,y1,x2,y2,x3,y3,s,p,a,b,c: real; BEGIN
write('Nhap vao toa do x1,y1 (0,0): );readIn(x1,y1);
write('Nhap vao toa do x2,y2 (1,0): ');readIn(x2,y2);
write(Nhap vao toa do x3,y3 (0,1): );readIn(x3,y8); a:=sqrt(sqr(x1-x2)+sqr(y1-y2)); qrt(sqr(@x1-x3)+sqr(y1-y3)); qrt(sqr(x3-x2)+sqr(y3-y2)); p:= (atb+©)/2; s := sqrt(p*(p-a)*(p-b)*(p-c)); writeln(‘Chu vi tam giac p= ',2*p,', dien tích tam giac = ',$); readin; END {Bai 1.11} Program Tam_giac_cho_canh_abc;
var ha,hb,he, (*do dai 3 duong cao”)
ma,mb,mc, (*do dai 3 duong trung tuyen*)
Trang 5la,Ib,lc, (“do dai 3 duong phan giac*) s\p.a.b,c.ri,R: real;
BEGIN
'write('Nhap vao ba canh tam giac (a,b,c)=(3,4,5): '); readin(a,b,c);
if(a+b<c)or(a+c<b)or(b+c<a) then begin
write(Khong phai 3 canh tam giac’); readin; exit; end; P:= (a+b+€)/2; s := sqrt(p*(p-a)*(p-b)*(p-e)); ha:=(2/a)°s;hb:=(2/b)*s;hc:=(2/e)*s; =sqrt(2*b*b+2*c*c-a*a)/2; qrt(2*a*a+2*e*c-b*b)/2; qrt(2*b“b+2*a*a-c*c)/2; :=2"sqrt(b*c*p*(p-a))/(b+e); Ib:=2*sqrt(a*c*p*(p-b))/(a+c); Ic ==2"sqrta b*p*(p-c))/(b+a); ;R:=a"b*c!4/S;
writeln('Chu vi tam giac p= ',2*p,', dien tich tam giac = '\s); 'writeln(Duong cao ha,hb,hc = ',ha,', ',hb,, ',h€);
writeln(Duong trung tuyen ma,mb,m‹ ,ma,, ',mb,, mc);
writeln(Duong phan giac la,lb,lc la,', “,hb,!, ',h€);
Trang 7BEGIN write(Nhap vao goc co so do theo do 0-360: ');readin(Goc); writein('Sin(',goc,’)=",sin(goc*pi/180)); writeln(Cos(',goc,)=',cos(goc*pi/180)); writein(‘tg(’,goc,’)=",sin(goc*pi/180)/cos(goc*pi/180)); writeln(‘Cotg(’,goc,"}=',cos(goc*pi/180)/sin(goc*pi/180)); readin; END {Bai 1.16,17 giải tương tự nhau} Program Tong_cac_chu_so; var So,t:integer; BEGIN
write(Nhap vao mot so co 2 chu so: ');readIn(so);
writeIn(‘Tong cac chu so cua no la: ', so div 10 + so mod 10); 'write(Nhap vao mot so co 3 chu so: ');readin(so); t:= so div 100 + so mod 10; $0:=so mod 100; tsttso div 10; 'writeln('Tong cac chu so cua no la: ', t); readin; END {Bai 1.18-19 tuong tu} Program Da_thuc_bac_hai; var a,b,¢,x:real; BEGIN
write('Nhap vao he so (a,b,c,x): ');readIn(a,b,c,x);
Trang 8{Bai 1.20}
Program Dien_tich_hinh_quat;
var R,alpha:real;
BEGIN
write('Nhap ban kinh (R): );readIn(R);
'write(Nhap goc quat: ');readin(alpha);
writeln(Dien tich hinh quat = ', Pi*R*R*alpha/360); Readin; END {Bai 1.21} Program khoang_cach; var x;y,A,B,C:real; BEGIN
write(‘Nhap toa do(x,y): ');readin(x,y);
write('Nhap tham so(A,B,C): ');readin(A,B,©);
writeln('Khoang cach H= ',ABS(A*x+B*y+C)/sqrt(A*A+B*B)); Readin; END {Bai 1.22} Program Goc_cos; var A,B,C,D, A1,B1,C1,D1:real; BEGIN
write(Nhap tham so(A,B,C,D): );readin(A,B,C,D);
write(Nhap tham so(A1,B1,C1,D1): ');readin(A1,B1,C1,D1); writeln(Khoang cach H= ', ABS(A*A1+B*B1+C*C1)/
(sqrl(A*A+B*B+C*C)*sqrt(A1*A1+B1*B1+C1*C1)); Readin;
END
Trang 9{Bai 1.23}
Program so_phuc;
var a1,b1,a2,b2:real; BEGIN
write(Nhap so phuc 1(a1,b1): );readin(a1,b1); write(Nhap so phuc 2(a2,b2): ');readIn(a2,b2); writeln('Tong hai so: (a,b), a1+a2,’ , ',b1+b2); writeln(‘Hiew hai so: (a,b), a1-a2,", ',b1-b2);
writeln(Tich hai so: (a,b)', a1*a2-b1*b2,', ',a1*b2+a2*b1); writeln(Chia hai so: (a,b)', (a1*a2+b1*b2)/(a2*a2+b2*b2),', ' ,(a1*b2-a2*b1)/(a2*a2+b2*b2)); Readin; END {Bai 1.24} Program Vat_roi; Const g=9.8; Var h, t,v,Ts:real; BEGIN
write('Nhap chieu cao(H): );readln(H);
write(‘Nhap thoi diem xet t: ');readin(t);
V;=gˆt,
Ts:=sqrt(2*h/g);
writeln(Van toc tai thoi diem t= ',v );
writeln(‘Thoi gian cham dat= ', Ts);
Readin; END
Trang 10Chương 2 Các lệnh có cấu trúc {Bai 2.1} Program Ham_so; var F,x:real; BEGIN
'write(Nhap vao gia trí (x): ');readin(x);
if (x>-1) and (x<=1) then f:= 5*x*x+5*x+1 else f:=abs(x-8)*(3*x"x+1);
'writeln('Gia tri cua ham F readin; END {Bai 2.2} Program Tinh_Luong; var ThucLinh,LuongChinh, SoNgayCong,PhuCap, TamUng,NgayNghi,LamThem:real; BEGIN write((Nhap vao cac gia tri (LuongChinh, SoNgayCong, PhuCap,TamUng, NgayNghi, LamThem): ‘); readin(LuongChinh, SoNgayCong, PhuCap, TamUng, NgayNghi, LamThem); ThucLinh:=(LuongChinh*SoNgayCong)/26+PhuCap-TamUng;
if NgayNghi>5 then ThucLinh :=0.8*Thuclinh;
if NgayNghi<3 then ThucLinh :=1.1*Thuclinh;
Trang 11BEGIN 'write(Nhap vao ba canh tam giac(a,b,c): '); readIn(a,b,c); if(a+b<c)or(a+c<b)or(b+c<a) then begin write(Khong phai 3 canh tam giac);readin;exit; end; p:=(atb+c/2); R:=a*b*cl(4*sqrt(p*(p-a)*(p-b)*(p-c))); x:=ai(2*R), write(x);readin; gA:=(180/pi)* ArcTan (x/sqrt (1-sqr (x))); x:=b/(2*R); gB:=(180/pi)* ArcTan (x/sqrt (1-sqr (x))); x:=c/(2*R); :=(180/pi)* ArcTan (x/sqrt (1-sqr (x))); writeln(‘Cac goc cua tam giac = (A,B,C),gA,, ',gB,', ',gC); readin; END {Bai 2.4) Program Phep_tinh; var i,n:integer; a,b ‘real; BEGIN
write(‘Nhap so thu a,b: ');readin(a,b);
Trang 12end; readin; END {Bai 2.5) Program Ngay_thang; var n,tinteger; BEGIN write(Nhap nam, thang : ');eadIn(n,); case n mod 4 of 0: case n mod 100 of 0: case t of
2:writeln( Thang nay co 28 ngay);
1,3,5,7,10,12:writeln(' Thang nay co 31 ngay); else 'writeln(' Thang nay co 30 ngay; end; else case t of
2:writeln(' Thang nay co 29 ngay);
1,3,5,7,10,12:writeln(' Thang nay co 31 ngay); else 'writeln(' Thang nay co 30 ngay'); end; end; else case t of
2:writeln(' Thang nay co 28 ngay;
Trang 13readin; END {Bai 2.7} Program Uoc_so; var i,n:integer; BEGIN
Trang 16end; if nt then writeln(‘So nguyen to: ' end; readin end {Bai 2.12} program p2_12; uses crt; var c: char; begin €lrscr; wrieln(Kytu MaASCII - Kytu MaASCI); for c := 'a' to 'z' do writeln(c:2, ord(c):10, upcase(c):16, ord(upcase(c)):10); readin; end {Bai 2.13} program p2_13; uses crt; var integer;
Ìf (a*a*a + b*b*b + c*c*c = 100*a + 10*b +c) then 'writeln(So do la: ',a,b,©);
readin end
Trang 17{Bai 2.14} program p2_14; uses crt; var n,a,b,c,d,e,f,t,k: longint; p:char, begin Clrscr; write(’Nhap so tien (trieu dong): '); readin(n); writeln(‘To 10000 To 5000 To 2000 To 1000 To500 To 200), pe; k:=0;
Trang 20writeln('So lon nhat: ', max); readin end, {Bai 2.18} Program Dan_so; var n :integer; A,x,t ‘real; k,s ‘real; BEGIN
writeln(‘ CHUONG TRINH TINH DAN SO ');
write(’ Nam bat dau (n) = ');readin(n); write(' Dan so nam do la A = ');readin(A);
write(' Nhap toc do tang dan so k(%) = ');readln(k);
Trang 25begin