Cho số tự nhiên n Hãy lập trình tính tổng sau s =1+1/2+1/3+...+1/n
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.
![](https://rs.olm.vn/images/avt/0.png?1311)
![](https://rs.olm.vn/images/avt/0.png?1311)
![](https://rs.olm.vn/images/avt/0.png?1311)
uses crt;
var i,n:integer;
s:longint;
begin
clrscr;
write('nhap n:');readln(n);
s:=0;
for i:=1 to n do
if i mod 2=1 then s:=s+i
else s:=s-i;
writeln('s= ',s);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
a) uses crt;
var n,x,i:longint;
lt:real;
begin
clrscr;
write('Nhap co so n=');readln(n);
write('Nhap so mu x='); readln(x);
lt:=1;
for i:=1 to x do
lt:=lt*n;
writeln(n,'^',x,'=',lt:0:0);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
Câu 1:
uses crt;
var i,n,t:integer;
begin
clrscr;
readln(n);
t:=0;
for i:=1 to n do
t:=t+i;
writeln(t);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
uses crt;
var s:real;
i,n:integer;
begin
clrscr;
readln(n);
s:=0;
for i:=1 to n do
s:=s+1/(i*(i+2));
writeln(s:4:2);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
var i,n: integer;
s:real;
begin
write(‘Nhập n: ‘); readln(n);
i:=1;
repeat
s:=s+1/i;
i:=i+1;
until i=n;
write(‘s =‘, s:0:4);
readln
end.
![diepbich](https://mtrend.vn/wp-content/litespeed/avatar/2424e83783e431b4a595c59b4f65d0ff.jpg)
Program Hotboy ;
Uses crt;
Var n,i,s : real;
Begin
Writeln(‘nhap n’); readln(n);
Repeat
S:=S+ 1/i;
I:=i+1 ;
Until n=i;
Writeln(‘S=’,S);
Readln
End.
![](https://rs.olm.vn/images/avt/0.png?1311)
Uses Crt;
Var i,S,n:integer;
Begin
Clrscr;
Readln(i,S,n);
For i:=1 to n do S:=S+i*i;
Write(S);
Readln
End.
uses crt;
var s,i,n:longint;
begin
clrscr;
readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i*i;
i:=i+1;
end;
writeln(s);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
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.
Tham khảo:
Uses Crt ;
Var i , n : Integer ;
tong: Real ;
BEGIN
Clrscr ;
Write (‘ Cho so tu nhien n : ‘) ; Readln (n) ;
tong :=0 ;
i :=1 ;
While i <= n Do
Begin
tong := tong + 1/i ;
i := i + 1 ;
End ;
Writeln (‘ Tong can tim la : ‘, tong:12:6 ) ;
Readln ;
END .