Câu 4:
fucntion tong(x:integer):integer;
var st:string;
d,i,n,y,t:integer;
begin
str(x,st);
d:=length(st);
t:=0;
for i:=1 to d do
begin
val(st[i],n,y);
t:=t+n;
end;
tong:=t;
end;
Câu 2:
const fi='bai2.inp'
fo='bai2.out'
var f1,f2:text;
a:array[1..100]of integer;
n,i,t:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(f2,t);
close(f1);
close(f2);
end.