Thứ Tư, 17 tháng 10, 2012

Một số chương trinh pascal tham khảo


Program cuuchuong;{CT nhap va xuat bang cuu chuong}
uses crt;
var so,tt :integer;
begin
clrscr;
write('nhap so : ');readln(so);
tt:=1;
repeat
writeln(so,' x ',tt:2,' = ',tt*so); tt:=tt+1;
until tt>10;
readln;
end.
Program tinh_tong;{CT tinh tong cong don}
{Tinh tong tu 1 den so nhap vao}
uses crt;
var so,tong,i:integer;
begin
clrscr;
write('nhap so :');readln(so);
tong:= 0; i:=1;
repeat
tong:=tong + i; i:= i + 1 ;
until ;
writeln('tong tu 1 den ', so,' la : ',tong:5);
readln;
end.
program doicho;{chuong trinh sap xep thu tu 3 so}
uses crt;
var so1,so2,so3,tam:integer;
begin clrscr;
write('nhap so thu nhat : ');readln(so1);
write('nhap so thu hai : ');readln(so2);
write('nhap so thu ba : ');readln(so3);
writeln('3 so da nhap chua sap xep',so1:5,so2:5,so3:5); if so1>so2 then
begin
tam:=so1;so1:=so2;so2:=tam;
end;
if so1>so3 then
begin
tam:=so1;so1:=so3;so3:=tam;
end;
if so2>so3 then
begin
tam:=so2;so2:=so3;so3:=tam;
end;
writeln('3 so da nhap da sap xep ',so1:5,so2:5,so3:5); readln;
end.

program amstrong;{CT xuat so amstrong }
uses crt; var a,b,c:integer;
begin
clrscr;
for a:=1 to 9 do
for b:=0 to 9 do
for c:=0 to 9 do
if(a*a*a + b*b*b + c*c*c = a*100 +b*10 +c)then writeln(a,b,c);
readln;
end.

Không có nhận xét nào:

Đăng nhận xét