0% found this document useful (0 votes)
12 views8 pages

Code Chung

The document contains 5 programming problems in Vietnamese. Each problem defines variables, constants, procedures and functions to solve a programming task. The tasks involve calculating sums of digits, factors, perfect numbers, longest runs of even/odd numbers in an array, and finding a student's rank and score.

Uploaded by

Quân Phan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

Code Chung

The document contains 5 programming problems in Vietnamese. Each problem defines variables, constants, procedures and functions to solve a programming task. The tasks involve calculating sums of digits, factors, perfect numbers, longest runs of even/odd numbers in an array, and finding a student's rank and score.

Uploaded by

Quân Phan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

BÀI 1:

var N, m, i, s, tong, dem:integer;

procedure tongchuso(n:integer);

begin

s:=0;

while (n > 0) do

begin

m:= n mod 10;

n:=n div 10;

s:=s+m;

end;

if s mod 9 = 0 then writeln ('Tong cac chu so cua N chia het cho 9')

else writeln ('Tong cac chu so cua n khong chia het cho 9');

end;

procedure tonguoc(n:integer);

begin

dem:= 0;

for i:=1 to n div 2 do

if n mod i = 0 then inc(dem);

writeln ('So cac uoc tu nhien cua ',n ,' la: ',dem);

end;

procedure hoanhao(n:integer);

begin

tong:=0;

for i:=1 to n div 2 do

if n mod i = 0 then tong:=tong+i;


if tong = n then writeln (n,' La so hoan hao')

else writeln (n,' Khong la so hoan hao');

end;

BEGIN

write ('nhap gia tri N:');

readln (n);

if n mod 2 = 0 then writeln (N, ' La so chan ')

else writeln (N, ' Khong la so chan');

tongchuso(n);

tonguoc(n);

hoanhao(n);

readln;

END.

BÀI 2:

var a, b, x:integer;

min,max, s1,s2,s:real;

BEGIN

write ('nhap cac gia tri a, b ,x:');

readln (a,b,x);

s1:=a*b;

s2:=x*(b-x)/2;

min:=s1;

max:=0;

for x:=1 to b do

begin

s:=s1-(a*x + x*(b-x) + b*(a-x))/2;


if min>s then min:=s;

if max<s then max:=s;

end;

writeln (s1:12:0);

writeln (s2:12:1);

writeln (max:12:1);

writeln (min:12:1);

readln;

END.

BÀI 3:

Program bai3_matkhau;

const fi='matkhau.inp';

fo='matkhau.out';

a:array['0'..'9'] of byte=(0,1,2,3,4,5,6,7,8,9);

var s:string;

n,i:integer;

t:longint;

f,g:text;

procedure nhap;

Begin

assign (f,fi); reset (f);

readln(f,s);

End;

function tong:longint;

begin
t:=0;

for i:=1 to length(s) do t:=t+a[s[i]];

tong:=t;

end;

procedure xuat;

Begin

assign (g,fo); rewrite (g);

write (g, tong);

End;

BEGIN

nhap;

xuat;

close(f);

close(g);

readln;

END.

Bài 4:

program day_chan_le;

const fi='DAYSO.INP';

fo='DAYSO.OUT';

var a:array[1..500] of integer;

n,i,d,max,vt,tg:integer;

f,g:text;

BEGIN

assign(f,fi); reset(f);

readln(f,n);
for i:=1 to n do read(f,a[i]);

d:=1; max:=0;

vt:=1; tg:=1;

for i:=1 to n-1 do

begin

if (abs(a[i])+abs(a[i+1])) mod 2 =1 then inc(d);

if (abs(a[i])+abs(a[i+1])) mod 2 = 0 then

begin

if max<d then

begin

max:=d; vt:=tg;

end;

tg:=i+1;

d:=1;

end;

end;

if max<d then

begin

max:=d; vt:=tg;

end;

assign(g,fo); rewrite(g);

writeln (g,max);

for i:=vt to vt+max-1 do write (g,a[i]:4);

close(f); close(g);

readln;

END.
BÀ I 5:

Program bai5_DTB;

{tim diem cua nguoi o vi thu k}

const fi='DTB.inp';

fo='DTB.out';

type mang=array[1..10000] of real;

var diem:mang;

n,k:integer;

vthu,sovthu:array[1..10000] of integer;

f,g:text;

procedure nhap;

var i:integer;

Begin

assign (f,fi); reset (f);

readln(f,n,k);

for i:=1 to n do read (f,diem[i]);

End;

Procedure sxkhongtang;

var i,j:integer;

tg:real;

Begin

for i:=1 to n-1 do

for j:=i+1 to n do

if diem[i]<diem[j] then

begin

tg:=diem[i];
diem[i]:=diem[j];

diem[j]:=tg;

end;

End;

Procedure xacdinhvthu;

var i,j:integer;

Begin

fillchar(sovthu,sizeof(sovthu),0);

for i:=1 to n do vthu[i]:=i;

for i:=1 to n-1 do

if diem[i]=diem[i+1] then vthu[i+1]:=vthu[i];

for i:=1 to n do

if vthu[i]>0 then inc(sovthu[vthu[i]]);

End;

Procedure inkqua;

Begin

assign(g,fo); rewrite(g);

if sovthu[k]<>0 then

begin

writeln(g,diem[k]:5:2);

if sovthu[k]>1 then

writeln(g, sovthu[k])

else writeln(g, 1);

end

else

writeln(g, 'Khong ‘);


End;

BEGIN

nhap;

sxkhongtang;

xacdinhvthu;

inkqua;

close(f);

close(g);

readln;

END.

You might also like