Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
a: uses crt;
var i,n:integer;
s:real;
begin
clrscr;
s:=0;
for i:=1 to 100 do s:=s+1/i;
writeln(s:4:2);
readln;
end.
b:
uses crt;
var i,n:integer;
s:real;
begin
clrscr;
s:=0;
i:=0;
while i<=100 do
begin
inc(i);
s:=s+1/i;
end;
writeln(s:4:2);
readln;
end.
a) Lỗi: Dư dấu ; sau từ do
b) Lỗi: While i>20 then (sửa: While i>20 do)
c) Lỗi: B=B+2; (sửa: B:=B+2;)
d) Lỗi: dư dấu ; sau từ do
e) Lỗi: S=S*2; (sửa: S:=S*2;)
f) Lỗi: i:=1 (sửa: i:=1;)
program fordo;
var i,n:longint;
s:real;
begin
write('N= ');readln(n);
s:=0;
for i:=1 to n do
s:=s+1/i;
writeln('Tong la ',s);
readln
end.
program whiledo;
var i,n:longint;
s:real;
begin
write('N= ');readln(n);
s:=0;i:=1;
While i<= n do
begin
s:=s+1/i;
i:=i+1;
end;
writeln('Tong la ',s);
readln
end.
b:
uses crt;
var i,n,s:integer;
begin
clrscr;
readln(n);
s:=0;
for i:=1 to n do s:=s+2*i;
writeln(s);
readln;
end.
c:
uses crt;
var i,n,s:integer;
begin
clrscr;
readln(n);
s:=0;
for i:=1 to n do s:=s+i;
writeln(s);
readln;
end.
d:
uses crt;
var i,n,s:integer;
begin
clrscr;
readln(n);
s:=0;
for i:=0 to n do s:=s+2*i+1;
writeln(s);
readln;
end.
While..do
Program HOC24;
var i: integer;
s: longint;
begin
s:=0; i:=1;
while i<=2018 do
begin
s:=s+i;
i:=i+1;
end;
write('S = ',s);
readln
end.
lệnh for...to...do:
a)program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
for i:=1 to 9 do s:=s+i;
write(s);
readln;
end.
b)
program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
for i:=1 to 14 do
begin
if i mod 2=0 then
s:=s+i;
end;
write(s);
readln;
end.
c)
program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
for i:=1 to 15 do
begin
if i mod 2=1 then
s:=s+i;
end;
write(s);
readln;
end.
lệnh while...do
a)program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
i:=1;
while i<=9 do
begin
s:=s+i;
i:=i+1;
end;
write(s);
readln;
end.
b)program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
i:=1;
while i<=14 do
begin
if i mod 2=0 then
s:=s+i
else i:=i+1;
end;
write(s);
readln;
end.
c)
program tinh_tong;
uses crt;
var i,s:byte;
begin
clrscr;
s:=0;
i:=1;
while i<=15 do
begin
if i mod 2=1 then
s:=s+i
else i:=i+1;
end;
write(s);
readln;
end.
a.
Var i : integer;
S : real;
Begin
S:= 0;
For i:=1 to 100 do S:= S + i;
Write (S);
Readln;
End.
b.
Var i : integer;
S : real;
Begin
S:= 0;
For i:=1 to 10 do S:= S + 1/i;
Write (S);
Readln;
End.
c.
Var i,n : integer;
S : real;
Begin
write ('n = '); read (n);
S:= 0;
For i:=1 to n do S:= S + i;
Write (S);
Readln;
End.
d.
Var i : integer;
S : real;
Begin
write ('n = '); read (n);
S:= 0;
For i:=1 to n do S:= S + 1/i;
Write (S);
Readln;
End.
Bài 1
a,
baif 2
a,