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.
program tinhtong;
var n,i : integer;
S : real;
begin
write('Nhap n: ');
readln(n);
i:=1;
S:=0;
while i<=n do
begin
S:=S+1/i;
i:=i+1;
end;
writeln('Tong S= ',S);
readln;
end.
program tinh_tong_S;
var
n, i: integer;
S: real;
begin
write('Nhap n: ');
readln(n);
S := 0;
i := 1;
while i <= n do
begin
S := S + 1 / i;
i := i + 1;
end;
writeln('Tong S la: ', S:0:2);
readln;
end.
*while..do
Program HOC24;
var i,n: integer;
s: real;
begin
write('Nhap n: '); readln(n);
i:=1;
while i<=n do
begin
s:=s+1/sqr(i);
i:=i+1;
end;
write('S= ',s:6:2);
readln
end.
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.
Bài 1:
uses crt;
var a:real;
i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
a:=0;
i:=1;
while i<=n do
begin
a:=a+1/i;
i:=i+1;
end;
writeln(a:4:2);
readln;
end.
Program HOC24;
var i,n: integer;
S: longint;
begin
write('Nhap N: '); readln(n);
i:=1; s:=0;
while i<=n do
begin
s:=s+i;
i:=i+2;
end;
write('S=',S);
readln
end.
program tinh_tong_S;
var
n, i, S: integer;
begin
write('Nhap n: ');
readln(n);
S := 0;
i := 1;
while i <= n do
begin
S := S + i;
i := i + 2;
end;
writeln('Tong S la: ', S);
readln;
end.
Cách 1 dùng lệnh for do:
Uses crt;
var i,n,k: integer;
begin clrcsr;
readln(n);
for i:=1 to n do begin
if(i mod 2=0) and (i>=10) then k:=k*i;
end;
writeln(k);
readln;
end.
Cách 2 dùng lệnh while do
Uses crt;
var m,n,o: integer;
begin clrcsr;
readln(n);
o:=1;
m:=1;
while (m<n) do begin
m:=m+1;
if(m mod 2=0) and (m>=10) then o:=o*m;
end;
writeln(o);
readln;
end.
program tong_for_to_do;
uses crt;
var i,n:integer;
t:real;
begin
clrscr;
write('nhap n:');readln(n);
t:=0;
for i:=1 to n do
if i mod 3=0 then t:=t+1/i;
writeln('tong la: ',t);
readln;
end.
program tong_while_do;
uses crt;
var i,n:integer;
t:real;
begin
clrscr;
write('nhap n:');readln(n);
t:=0;i:=3;
while i<=3*n do
begin
t:=t+1/i;
i:=i+3;
end;
writeln('tong la: ',t);
readln;
end.
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.