[Pascal] Izračunavanje sume
Poslato: Ponedeljak, 17. Novembar 2014, 16:06
Napisati program koji za zadatu tačnost [inlmath]eps[/inlmath] izračunava broj:
[dispmath]S=\frac{4}{1\cdot 2\cdot 3\cdot 2^2}+\frac{8}{2\cdot 3\cdot 4\cdot 2^3}+\frac{12}{3\cdot 4\cdot 5\cdot 2^4}+\frac{16}{4\cdot 5\cdot 6\cdot 2^5}+\cdots[/dispmath]
Da li je dobar ovaj moj kod:
[dispmath]S=\frac{4}{1\cdot 2\cdot 3\cdot 2^2}+\frac{8}{2\cdot 3\cdot 4\cdot 2^3}+\frac{12}{3\cdot 4\cdot 5\cdot 2^4}+\frac{16}{4\cdot 5\cdot 6\cdot 2^5}+\cdots[/dispmath]
Da li je dobar ovaj moj kod:
- Kôd: Obeleži sve
program suma;
var br,im,a,b,c,d,i,j:integer; s,eps:real;
begin
write('Unesi zeljenu tacnost:');
readln(eps);
a:=1;
b:=2;
c:=3;
j:=2;
s:=1/6;
br:=4;
repeat
d:=2;
for i:=1 to j do
d:=d*2;
a:=a+1;
b:=b+1;
c:=c*1;
im:=a*b*c*d;
br:=br+4;
s:=s+br/im;
j:=j+1;
until(br/im<eps);
write(s:2:6);
end.