Viết CT tính các tổng sau a, S=1+2+3+…+N b,S=1+3+5+…+N c,S=1+1/2+1/3+…+1/n d,S=1/2+1/(2*3)+1/(3*4)+…+1/((n-1)*n) 15/07/2021 Bởi Julia Viết CT tính các tổng sau a, S=1+2+3+…+N b,S=1+3+5+…+N c,S=1+1/2+1/3+…+1/n d,S=1/2+1/(2*3)+1/(3*4)+…+1/((n-1)*n)
a) uses crt; var n,i,s:integer; begin clrscr; write(‘Nhap n: ‘); readln(n); s:=0; for i:=1 to n do s:=s+i; write(‘S= ‘,s); readln; end. b) uses crt; var n,i,s:integer; begin clrscr; write(‘Nhap n: ‘); readln(n); s:=0; for i:=1 to n do if i mod 2=1 then s:=s+i; write(‘S= ‘,s); readln; end. c) 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/i; write(‘S= ‘,s:0:3); readln; end. d) uses crt; var n,i:integer; s:real; begin clrscr; write(‘Nhap n: ‘); readln(n); s:=0; for i:=2 to n do s:=s+1/((i-1)*i); write(‘S= ‘,s:0:3); readln; end. Bình luận
b) var n,i,s:longint; begin write(‘N= ‘);readln(n); s:=0; for i:=1 to n do if i mod 2=1 then s:=s+i; writeln(‘s= ‘,s); readln; end. c) var i,n:integer; 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(‘s=’,s:2:3); readln; end. Bình luận
a)
uses crt;
var n,i,s:integer;
begin
clrscr;
write(‘Nhap n: ‘); readln(n);
s:=0;
for i:=1 to n do
s:=s+i;
write(‘S= ‘,s);
readln;
end.
b)
uses crt;
var n,i,s:integer;
begin
clrscr;
write(‘Nhap n: ‘); readln(n);
s:=0;
for i:=1 to n do
if i mod 2=1 then s:=s+i;
write(‘S= ‘,s);
readln;
end.
c)
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/i;
write(‘S= ‘,s:0:3);
readln;
end.
d)
uses crt;
var n,i:integer;
s:real;
begin
clrscr;
write(‘Nhap n: ‘); readln(n);
s:=0;
for i:=2 to n do
s:=s+1/((i-1)*i);
write(‘S= ‘,s:0:3);
readln;
end.
b)
var n,i,s:longint;
begin
write(‘N= ‘);readln(n);
s:=0;
for i:=1 to n do
if i mod 2=1 then
s:=s+i;
writeln(‘s= ‘,s);
readln;
end.
c) var i,n:integer;
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(‘s=’,s:2:3);
readln;
end.