PDA

View Full Version : 10 bài tin thi HK


rongphuongdong
23-01-2009, 09:19 PM
Bài 1:
Program abc;
var n,s,i,k:integer;
begin
write(' Nhap N: ');Read(N);
S:=0;
For i:=0 to N-1 do
If i mod 3 = 0 then S:=S+i;
k:=(n-1) div 3;
For i:=0 to k-1 do
Write(3*i,'+');Write(k*3,' =',S);
Readln;
Readln;
End.

Bài 2:
Program abc;
var N,i:integer;
S:real;
begin
Write('Nhap N: ');Read(N);
S:=1;
for i:=1 to n do
s:=s+1/(2*i);
Write('1+');
For i:=1 to n-1 do
Write('1/',2*i,' + ');
Write('1/',2*n,'= ',S:6:3);
readln;
readln;
end.

Bài 3:
Program cong_hai_phan_so;
Var a,b,c,d: integer;
x,y,x1,y1,x2,y2: integer;
Begin
Repeat
Write(' Tu thu 1: '); readln(a);
Write(' Mau thu 1: '); readln(b);
Write(' Tu thu 2: '); readln(c);
write(' Mau thu 2: '); readln(d);
until (b<>0) and (d<>0);
x:= a*d+b*c; x1:=x; y:=b*d; y1:=y;
while x1<>y1 do
if x1>y1 then x1:=x1-y1 else y1:= y1-x1;
x2:= x div x1; y2:= y div x1;
If (x2 mod y2 =0) then
Write(A,'/',B,'+',C,'/',D,'= ',x2 div y2)
else Write(A,'/',B,'+',C,'/',D,'= ',x2,'/',y2);
Readln;
Readln;
End.

Bài 4:

Program Pitago;
var a,b,c,i:longint;
Begin
For a:=1 to 297 do
For b:=a+1 to 298 do
For c:=b+1 to 299 do
If sqr(a)+sqr(b)=sqr(c) then
begin
writeln(a:5,b:5,c:5);
readln;
end;
End.

Bài 5:
Program tong_chanle;
var A: array[1..100] of integer;
i,n,chan,le: integer;
Begin
Write(' Nhap N:');Read(N);
For i:=1 to N do
begin
write('A[',i,']= ');Readln(A[i]);
end;
chan:=0; le:=0;
For i:=1 to N do
If A[i] mod 2 =0 then chan:=chan+A[i]
else le:=le+A[i];
writeln(' Tong cac so chan: ',chan);
writeln(' Tong cac so le : ',le);
readln;
readln
End.

Bài 6:
Program baiso6;
const nmax=100;
var A: array[1..nmax] of integer;
n,k,i,dem: integer;
Begin
Write(' Nhap N= ');Readln(N);
Writeln(' Nhap day so nguyen:');
For i:=1 to N do
begin
write(' A[',i,']= '); Readln(A[i]);
end;
Write('Nhap khoa k = '); Read(k);
dem:=0;
For i:=1 to N do
If A[i]<k then dem:=dem+1;
Write(' Co ',dem,' phan tu nho hon ',k);
Readln;
Readln;
End.

Bài 7:
Program xepten;
var s,s1,s2:string;
x,i,j,n:integer;
Begin
Write(' Nhap ho ten: ');Read(s);
x:=length(s);
n:=0;
For i:=x downto 1 do
If s[i]=' ' then n:=i;
s1:=copy(s,n+1,x-n);
s2:=copy(s,1,n-1);
Writeln(s1+' '+s2);
Readln;
Readln;
End.
{Write by Nguyen Van Huu 11a1}

Bài 8:
Program xoakitu;
var s,s1,s3:string;
s2: array[0..10] of string;
x,i,j:integer;
dem:array[0..100] of integer;
Begin
Write(' Nhap xau s: ');Read(s);
s1:='0123456789 ';
For i:=0 to 10 do
s2[i]:=copy(s1,i+1,1);
For j:=1 to x do dem[j]:=0;
x:=length(s);
s3:=''; {Khoi tao xau rong s3}
For j:=1 to x do
For i:=0 to 10 do
If s[j]<>s2[i] then dem[j]:=dem[j]+1;
For j:=1 to x do
If dem[j]=11 then s3:=s3+s[j]; {Tao xau s3}
Write('Xau sau khi xoa la ',s3);
Readln;
Readln;
End.

Bài 9:
Program songuyento;
var A,dem:array[1..100] of integer;
n,i,j:integer;
Begin
Write(' Nhap N= ');Read(N);
Writeln(' Nhap day so nguyen');
For i:=1 to N do
Begin
write(' A[',i,']= ');Readln(A[i]);
dem[i]:=0;
end;
For i:=1 to N do
Begin
For j:=2 to trunc(sqrt(A[i])) do
If (A[i] mod j<>0) then dem[i]:=dem[i]+1;
end;
For i:=1 to N do
If (dem[i]= trunc(sqrt(A[i]))-1) and (A[i]<>1) then
write(a[i]:4);
readln;
readln
end.

Bài 10:
Program Phibonaxi;
var F:array[0..100] of integer;
N,i,dem:integer;
Begin
Write('Nhap N= ');Read(N);
F[0]:=0; F[1]:=1;
i:=1;dem:=0;
While F[i]<N do
begin
dem:=dem+1;
i:=i+1;
F[i]:=F[i-1]+F[i-2];
end;
If (dem<>0) or (n=1) then
Writeln('Cac so trong day Phibonaxi nho hon ',N);
If n=0 then write('Khong co so nao');
For i:=0 to dem do
iF N<>0 THEN Write(F[i]:3);
Readln;
Readln;
END.