hoangpascal-cau3diem

Bai1: Giai he phuong trinh

program giaihept;

uses crt;

var a,b,c,d,e,f,dx,dy, dt: real;

begin

clrscr;

write('nhap vao so a,b,c'); readln(a,b,c);

write('nhap vao so d,e,f'); readln(d,e,f);

dt:= a*e - d*b;

dx:=c*e- b*f;

dy:=a*f-c*d;

if dt= 0 then write('he phuong trinh da cho vo nghiem')

else

begin

writeln('x= ',dx/dt:7:2);

writeln('y= ', dy/dt:7:2);

end;

readln;

end.

Bai 2: Giai phuong trinh bac 2

program phtrinhb2;

uses crt;

var a,b,c,delta,x1,x2: real;

begin

clrscr;

write('nhap vao ba he so a,b,c '); readln(a,b,c);

delta:= b*b-4*a*c;

if delta < 0 then

begin

write('phuong trinh da cho vo nghiem , xin moi nhap lai he so');

end

else

begin

if delta =0 then write('phuong trinh co nghiem kep x1= x2= ',-b/(2*a))

else writeln('phuong trinh co hai nghiem phan biet x1= ',(-b+sqrt(delta))/(2*a):7:2 ,

' va x2 = ', (-b+sqrt(delta))/(2*a):7:2);

end;

readln;

end.

Bai 3: tim gia tri maxmin

program timminmax;

uses crt;

var i,j,n,vtmax,vtmin: integer;

a :array[1..100] of real;

max,min : real;

begin

clrscr;

write('nhap vao so luong phan tu cua day '); readln(n);

for i:= 1 to n do

begin

write('nhap vao gia tri phan tu thu ',i,' = '); readln(a[i]);

end;

max:= a[1]; vtmax:= 1;

for i:=1 to n do

if a[i] > max then

begin

max:=a[i]; vtmax:=i;

end;

writeln('gia tri lon nhat la',max:7:2);

writeln('vi tri cua gia tri lon nhat la',vtmax);

min:=a[1]; vtmin:=1;

for j:= 1 to n do

if a[j] < min then

begin

min:= a[j]; vtmin:=j;

end;

writeln('gia tri nho nhat la ',min:7:2);

write('vi tri cua gia tri nho nhat la',vtmin);

readln;

end.

bai 4:Tim maxmin cua ma tran

uses crt;

label 1,2,3;

var a:array[1..20,1..20] of integer;

n,h,k,i,j,max,min:integer;

r:char;

Begin

clrscr;

Write(' Hay Nhap Vao so hang va cot Cua Ma Tran A:'); Readln(n,h);

For I:=1 to n do For J:=1 to h do

begin

Write('A[',i,',',j,']'); Readln(a[i,j]); k:=k+1;

If k=1 then begin max:=a[1,1]; min:=a[1,1]; end;

If A[i,j]>max then max:=a[i,j];

If a[i,j]<min then min:=a[i,j];

end;

For I:=1 To n do

begin

For j:=1 to h do

write(' ',a[i,j]);

Writeln;

end;

Writeln(' Gia Tri Lon Nhat la:',max);

Writeln(' Gia Tri Be Nhat La:', min);

Readln;

End.

Bai 5:Nhan 2 ma tran

program nhanmatran;

uses crt;

var

i,j,k :integer;

n,m,p: integer;

a,b,c: array[1..100,1..100] of integer;

begin

clrscr;

write('nhap vao so hang cua ma tran A'); readln(n);

write('nhap vao so cot cua ma tran A'); readln(m);

write('nhap vao so hang cua ma tran B'); readln(m);

write('nhap vao so cot cua ma tran B'); readln(p);

for i:= 1 to n do

for j:=1 to m do

begin

write('a[',i,',',j,'] := '); readln(a[i,j]);

end;

for i:=1 to m do

for j:=1 to p do

begin

write('b[',i,',',j,'] := '); readln(b[i,j]);

end;

writeln('Ma tran A'); for i:= 1 to n do

begin for j:=1 to m do

write(' ',a[i,j] ,' ');

writeln;

end;

writeln('ma tran B');

for i:=1 to m do

begin

for j:=1 to p do

write(' ',b[i,j] , '');

writeln;

end;

for i:=1 to n do

for j:=1 to p do

for k:=1 to m do

c[i,j] := c[i,j] +a[i,k]* b[k,j];

writeln(' Ma tran A*B' );

for i:=1 to n do

begin

for j:=1 to m do

write(' ', c[i,j],'');

writeln;

end;

readln;

end.

Bai 6:Dem tong so duong va tong so am

uses crt;

var n,i,sd,sa,tongduong,tongam:integer;

h:char;

BEGIN

clrscr;

Writeln('Hay Nhap Vao So Luong Phan Tu Cua Day: ');

Readln(n);

Writeln(' Hay Nhap Cac Phan Tu Cua Day: ');

For I:=1 to n do

Begin

Readln(n);

If n>0 then begin sd:=sd+1;TongDuong:=TongDuong+n; end;

If n<0 then begin sa:=sa+1;TongAm:=TongAm+n; end;

end;

If sd=0 then Writeln(' Khong Co So Duong Nao Trong Day So :') else

Writeln(' So Phan Tu Duong Trong Day La:',sd,' Gia Tri Trung Binh La:',TongDuong/sd:8:2);

If sa=0 then Writeln(' Khong Co So Am Nao Trong Day So:') else

Writeln(' So Phan Tu Am Trong Day La:',sa,' Gia Tri Trung Binh La:',TongAm/sa:8:2);

readln;

end.

Bai 7:Ngay thang nam

uses crt;

var nam,ngay,thang:integer;

h:char;

BEGIN

clrscr;

Writeln(' Nhap Nam:'); Readln(nam);

Writeln(' Nhap Thang:'); Readln(thang);

Case thang of

1,3,5,7,8,10,12: ngay:=31;

4,6,9,11: ngay:=30;

else

If nam mod 4= 0 then ngay:=29 else ngay:=28;

end;

Writeln(' Nam ',nam,' Thang ',thang,' Co ',ngay,' ngay');

readln;

ENd.

Bai 9:Thu nhap GDP

uses crt;

Var nam:word;

GDP,TD,BD:real;

h:char;

begin

clrscr;

Writeln(' Hay Nhap Vao Thu Nhap GDP Cua Nuoc Ta Nam 2000(USD/Nguoi:'); readln(GDP);

Writeln(' Hay Nhap Vao Toc Do Tang Truong Hang Nam(%):'); readln(TD);

nam:=2000;

BD:=GDP;

Writeln(' NAM GDP');

While GDP<=2*BD do

begin

Writeln(' ',nam,' ',GDP:8:2);

GDP:=GDP+GDP*TD/100;

nam:=nam+1;

end;

Writeln(' ',nam,' ',GDP:8:2);

Readln;

End.

Bai 10: sap xep tang dan

uses crt;

var a: array[1..100] of real;

b: array[1..100] of real;

tg: real;

i,n,j: integer;

begin

clrscr;

writeln(' nhap n');

readln(n);

for i :=1 to n do

begin

writeln(' nhap so thu ',i);

readln(a[i]);

b[i]:= a[i];

end;

for i:=1 to n do

begin

for j:=1 to n do

begin

if a[i] < a[j] then

begin

tg:=a[j];

a[j]:=a[i];

a[i]:=tg;

end;

end;

end;

write('day ban dau: '); for i:=1 to n do write(b[i]:2:0);

writeln(' ');

write('day sap xep: '); for i:=1 to n do write(a[i]:2:0);

readln;

end.

Bai 12:Tim uoc chung lon nhat

program ucln;

uses crt;

var a,b,c : integer;

begin

clrscr;

write('nhap vao 2 so a,b'); readln(a,b);

while a> 0 do

begin

if b>a then

begin

c:=a;

a:=b;

b:=c;

end;

a:=a-b;

end;

writeln('uoc chung lon nhat la ',b);

readln;

end.

Bai 13: Tim boi chung nho nhat

program boichungnn;

uses crt;

var a,b,x,y,r,us,bs : integer;

begin

clrscr;

write('nhap vao a,b '); readln(a,b);

x:=a ; y:=b;

if a<b then

begin

r:=a; a:=b ; b:=r;

end;

while b>0 do

begin

r:= a mod b;

a:=b;

b:=r;

end;

us:=a;

bs:=(x*y) div us;

writeln('boi chung nho nhat la ',bs);

readln;

end.

Bai 14: Tinh tong

program tinhtong;

uses crt;

var i,j,n,t : integer; s: real;

begin

s:=0;

write('nhap vao so n'); readln(n);

for i:=1 to n do

begin

t:=1;

for j:= 1 to i do t:= t*j;

s:= s+ 1/t;

end;

write(' tong S = ',s:7:2);

readln;

end.

Bai 15: Tinh giai thua

program tinhgiaithua;

uses crt;

var i,n,gt : longint;

begin

clrscr;

write('nhap vao so n'); readln(n);

gt:=1;

if n> 1 then

for i:=2 to n do

gt:=gt*i;

writeln('giai thua cua so do la ',gt);

readln;

end.

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: