viết chương trình tính tổng s=1+\(\dfrac{1}{1\cdot2}\)+\(\dfrac{1}{2\cdot3}+\dfrac{1}{3\cdot4}\)+............+\(\dfrac{1}{n\left(n+1\right)}\)với n là số nguyên nhập từ bàn phím.
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)
Bài 1:
uses crt;
var n,i:integer;
s:real;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
for i:=1 to n do
s:=s+1/(2*i+1);
writeln(s:4:2);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
Đặt A=\(\dfrac{1}{1.2.3}\)+\(\dfrac{1}{2.3.4}\)+\(\dfrac{1}{3.4.5}\)+...+\(\dfrac{1}{n\left(n+1\right)\left(n+2\right)}\)
=>2A=\(\dfrac{2}{1.2.3}\)+\(\dfrac{2}{2.3.4}\)+...+\(\dfrac{2}{n\left(n+1\right)\left(n+2\right)}\)
=\(\dfrac{1}{1.2}-\dfrac{1}{2.3}+\dfrac{1}{2.3}-\dfrac{1}{3.4}+...+\)\(\dfrac{1}{n\left(n+1\right)}-\dfrac{1}{\left(n+1\right)\left(n+2\right)}\)
=\(\dfrac{1}{2}-\dfrac{1}{\left(n+1\right)\left(n+2\right)}\)
=\(\dfrac{\left(n+1\right)\left(n+2\right)-2}{2\left(n+1\right)\left(n+2\right)}\)
=\(\dfrac{n^2+3n}{2\left(n^2+3n+2\right)}\)
=>A=\(\dfrac{n^2+3n}{4n^2+12n+8}\)
![](https://rs.olm.vn/images/avt/0.png?1311)
Lời giải:
Ta có: \(\frac{1}{k(k+1)(k+2)}=\frac{1}{2}.\frac{2}{k(k+1)(k+2)}=\frac{1}{2}.\frac{(k+2)-k}{k(k+1)(k+2)}\)
\(=\frac{1}{2}\left(\frac{k+2}{k(k+1)(k+2)}-\frac{k}{k(k+1)(k+2)}\right)=\frac{1}{2}\left(\frac{1}{k(k+1)}-\frac{1}{(k+1)(k+2)}\right)\)
Áp dụng vào bài toán:
\(\frac{1}{1.2.3}=\frac{1}{2}\left(\frac{1}{1.2}-\frac{1}{2.3}\right)\)
\(\frac{1}{2.3.4}=\frac{1}{2}\left(\frac{1}{2.3}-\frac{1}{3.4}\right)\)
\(\frac{1}{3.4.5}=\frac{1}{2}\left(\frac{1}{3.4}-\frac{1}{4.5}\right)\)
.......
\(\frac{1}{n(n+1)(n+2)}=\frac{1}{2}\left(\frac{1}{n(n+1)}-\frac{1}{(n+1)(n+2)}\right)\)
\(\Rightarrow B=\frac{1}{2}\left(\frac{1}{1.2}-\frac{1}{2.3}+\frac{1}{2.3}-\frac{1}{3.4}+\frac{1}{3.4}-\frac{1}{4.5}+...+\frac{1}{n(n+1)}-\frac{1}{(n+1)(n+2)}\right)\)
\(=\frac{1}{2}\left(\frac{1}{1.2}-\frac{1}{(n+1)(n+2)}\right)=\frac{1}{4}-\frac{1}{2(n+1)(n+2)}\)
![](https://rs.olm.vn/images/avt/0.png?1311)
\(B=\dfrac{1}{2}\left(\dfrac{2}{1\cdot2\cdot3}+\dfrac{2}{2\cdot3\cdot4}+...+\dfrac{2}{n\left(n+1\right)\left(n+2\right)}\right)\)
\(=\dfrac{1}{2}\left(\dfrac{1}{1\cdot2}-\dfrac{1}{2\cdot3}+\dfrac{1}{2\cdot3}-\dfrac{1}{3\cdot4}+...+\dfrac{1}{n\cdot\left(n+1\right)}-\dfrac{1}{\left(n+1\right)\left(n+2\right)}\right)\)
\(=\dfrac{1}{2}\left(\dfrac{1}{2}-\dfrac{1}{\left(n+1\right)\left(n+2\right)}\right)\)
\(=\dfrac{1}{2}\cdot\dfrac{n^2+3n+2-2}{2\left(n+1\right)\left(n+2\right)}=\dfrac{n\left(n+3\right)}{4\left(n+1\right)\left(n+2\right)}\)
![](https://rs.olm.vn/images/avt/0.png?1311)
a) Ta có
S = \(\dfrac{1}{1.2.3}+\dfrac{1}{2.3.4}+\dfrac{1}{3.4.5}+...+\dfrac{1}{n.\left(n+1\right).\left(n+2\right)}\)
2S = \(\dfrac{2}{1.2.3}+\dfrac{2}{2.3.4}+\dfrac{2}{3.4.5}+...+\dfrac{2}{n.\left(n+1\right).\left(n+2\right)}\)
2S = \(\dfrac{1}{1.2}-\dfrac{1}{2.3}+\dfrac{1}{2.3}-\dfrac{1}{3.4}+\dfrac{1}{3.4}-\dfrac{1}{4.5}+...+\dfrac{1}{n\left(n+1\right)}-\dfrac{1}{\left(n+1\right).\left(n+2\right)}\)2S = \(\dfrac{1}{1.2}-\dfrac{1}{\left(n+1\right).\left(n+2\right)}\)
S = \(\dfrac{1}{4}-\dfrac{1}{\left(n+1\right).\left(n+2\right):2}\)
b) A = \(1+\dfrac{1}{3}+\dfrac{1}{5}+\dfrac{1}{7}+...+\dfrac{1}{99}\)
A = \(2-\dfrac{1}{3}+\dfrac{1}{3}-\dfrac{1}{5}+\dfrac{1}{5}-\dfrac{1}{7}+...+\dfrac{1}{97}-\dfrac{1}{99}\)
A = \(2-\dfrac{1}{99}\)
A = \(\dfrac{197}{99}\)
c) Ta có
B = \(\dfrac{1}{2}+\dfrac{1}{3}+\dfrac{1}{4}+...+\dfrac{1}{100}\)
B = \(1-\dfrac{1}{2}+\dfrac{1}{2}-\dfrac{1}{3}+\dfrac{1}{3}-\dfrac{1}{4}+...+\dfrac{1}{99}-\dfrac{1}{100}\)
B = \(1-\dfrac{1}{100}\)
B = \(\dfrac{99}{100}\)
d) Ta có
C = \(\dfrac{99}{1}+\dfrac{98}{2}+\dfrac{97}{3}+...+\dfrac{1}{99}\)
C = \(1+\left(1+\dfrac{98}{2}\right)+\left(1+\dfrac{97}{3}\right)+...+\left(1+\dfrac{1}{99}\right)\)
C = \(1+50+\dfrac{100}{3}+...+\dfrac{100}{99}\)
C = 51 + 100(\(\dfrac{1}{3}+\dfrac{1}{4}+\dfrac{1}{5}+...+\dfrac{1}{99}\))
Đặt D = \(\dfrac{1}{3}+\dfrac{1}{4}+\dfrac{1}{5}+...+\dfrac{1}{99}\)
D = \(\dfrac{1}{2}-\dfrac{1}{3}+\dfrac{1}{3}-\dfrac{1}{4}+\dfrac{1}{4}-\dfrac{1}{5}+...+\dfrac{1}{98}-\dfrac{1}{99}\)
D = \(\dfrac{1}{2}-\dfrac{1}{99}\)
D = \(\dfrac{97}{198}\)
=> C = 51 + 100.\(\dfrac{97}{198}\)
C = 51 + \(\dfrac{4850}{99}\)
C = \(\dfrac{9899}{99}\)
Đây là bài làm của mình sai thì nx nha
![](https://rs.olm.vn/images/avt/0.png?1311)
program bai1;
var n,i:longint;s:real;
begin
write('N= ');readln(n);
s:=0;
for i:=1 to n do
s:=s+1/(i*(i+2));
writeln('Tong la ',s);
readln
end.
của Trương Quang Dũng thiếu uses crt;
ko khai báo s.
có 2 dấu ngoặc liên tiếp nên chương trình sẽ bị lỗi
var i,n:integer;
s:real;
begin
s:=1;
write('ban hay nhap vao mot so nguyen: '); readln(n);
for i:= 1 to n do
s:= s + (1/(i*(i+1));
writeln(' tong s = ',s:0:2);
readln
end.
var i,n:integer;
s:real;
begin
s:=1;
write('ban hay nhap vao mot so nguyen: '); readln(n);
for i:= 1 to n do
s:= s + (1/(i*(i+1));
writeln(' tong s = ',s:0:2);
readln
end.