Những câu hỏi liên quan
Ngân
Xem chi tiết
ILoveMath
3 tháng 3 2022 lúc 9:21

For...do:

var s,i: integer;

begin

readln(s,i);

s:=0;

For i:=3 to 99 do

If i mod 3 = 0 do s:=s+i;

write(s)

readln;

end.

while ... do:

Var i,S:integer;

Begin

Readln(i,s);

S:=0;

i:=3;

while i<=99 do

if i mod 3 = 0 then s:=s+i;

write(s);

Readln;

End.

Bình luận (0)
 ILoveMath đã xóa
ILoveMath
3 tháng 3 2022 lúc 10:29

For...do:

var s,i: integer;

begin

readln(s,i);

s:=0;

For i:=3 to 99 do

If i mod 3 = 0 do s:=s+i;

write(s);

readln;

end.

while ... do:

Var i,S:integer;

Begin

Readln(i,s);

S:=0;

i:=3;

while i<=99 do

if i mod 3 = 0 then s:=s+i;

write(s);

Readln;

End.

Bình luận (0)
Lý Tâm Như
Xem chi tiết
nguyễn an phát
27 tháng 5 2021 lúc 21:09

program tinh_tong;

uses crt;

var i,n:integer;

s:real;

begin

clrscr;

write('nhap n:');readln(n);

for i:=1 to n*2-1 do

if i mod 2=1 then s:=s+1/i;

writeln('tong la: ',s);

readln;

end.

Bình luận (0)
nguyễn an phát
27 tháng 5 2021 lúc 21:11

program tinh_tong;

uses crt;

var i,n:integer;

s:real;

begin

clrscr;

write('nhap n:');readln(n);

i:=1;

while i<=n*2-1 do

begin

s:=s+1/i;

i:=i+2;

end;

writeln('tong la: ',s);

readln;

end.

Bình luận (0)
Trí So Sad
Xem chi tiết
Nguyễn Lê Phước Thịnh
22 tháng 4 2021 lúc 21:38

a)

uses crt;

var s,i,n:integer;

begin

clrscr;

write('nhap n='); readln(n);

s:=0;

for i:=1 to n do 

  s:=s+i;

writeln(s);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
22 tháng 4 2021 lúc 21:38

b) 

uses crt;

var s,i,n:integer;

begin

clrscr;

write('nhap n='); readln(n);

s:=0;

i:=1;

while i<=n do 

  begin

s:=s+i;

inc(i);

end;

writeln(s);

readln;

end.

Bình luận (1)
KhanhHuy
Xem chi tiết
nguyễn an phát
21 tháng 3 2021 lúc 19:06

lệnh for...to...do:

a)program tinh_tong;

uses crt;

var i,s:byte;

begin

  clrscr;

  s:=0;

  for i:=1 to 9 do s:=s+i;

  write(s);

readln;

end.

b)

program tinh_tong;

uses crt;

var i,s:byte;

begin

  clrscr;

  s:=0;

  for i:=1 to 14 do

begin

if i mod 2=0 then

s:=s+i;

end;

  write(s);

readln;

end.

c)

program tinh_tong;

uses crt;

var i,s:byte;

begin

  clrscr;

  s:=0;

  for i:=1 to 15 do

begin

if i mod 2=1 then

s:=s+i;

end;

  write(s);

readln;

end.

lệnh while...do

a)program tinh_tong;

uses crt;

var i,s:byte;

begin

  clrscr;

  s:=0;

  i:=1;

while i<=9 do

begin

  s:=s+i;

i:=i+1;

end;

  write(s);

readln;

end.

b)program tinh_tong;

uses crt;

var i,s:byte;

begin

  clrscr;

  s:=0;

  i:=1;

while i<=14 do

begin

if i mod 2=0 then

  s:=s+i

else i:=i+1;

end;

  write(s);

readln;

end.

c)

program tinh_tong;

uses crt;

var i,s:byte;

begin

  clrscr;

  s:=0;

  i:=1;

while i<=15 do

begin

if i mod 2=1 then

  s:=s+i

else i:=i+1;

end;

  write(s);

readln;

end.

Bình luận (0)
Linh Nhi
Xem chi tiết
Nguyễn Lê Phước Thịnh
4 tháng 3 2022 lúc 9:22

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ình luận (0)
Tùng Dương
Xem chi tiết
nguyễn an phát
27 tháng 5 2021 lúc 13:35

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.

Bình luận (0)
nguyễn an phát
27 tháng 5 2021 lúc 13:37

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.

Bình luận (0)
SuperMeo
Xem chi tiết
Trungnghia
10 tháng 4 2021 lúc 16:20

a, Với lệnh For..do:
Var i:integer;
          S:real; (Hoặc S:longint);
       Begin
    S:=0;
       For i:=1 to 1980 do S:=S+i;
      Writeln('Vay tong cua S=',S);
     Readln
    End.
*In đậm: Bạn có thể chọn 1/2 cách với S:real hay S: longint. Chỉ là nếu bạn muốn nhìn dễ hiểu hơn thì tùy bạn. H/ảnh minh họa như dưới đây :D (Đã thử và áp dụng cách này với For...do)
undefinedundefined

b, Với lệnh While...do
Var i:integer;
      S:real;
Begin
  S:=0; i:=0;
While i<=1980 do
  Begin
     S:= S+i;
       i:= i+1;
End;
Writeln('Vay tong cua S=',S);
Readln
End.
*In đậm: Cũng có thể dùng S:longint (70-80% đúng) thay vì S:real (100% đúng). Nhưng khuyến cáo nên sử dụng S:real (Đã thử và áp dụng tương đối chính xác với While...do)
Good luck for you!!! :D

 

Bình luận (0)
Nguyễn Lê Phước Thịnh
10 tháng 4 2021 lúc 20:14

a) uses crt;

var s,i:longint;

begin

clrscr;

s:=0;

for i:=1 to 1980 do 

  s:=s+i;

writeln(s);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
10 tháng 4 2021 lúc 20:14

b) uses crt;

var s,i:longint;

begin

clrscr;

s:=0;

i:=1;

while i<=1980 do 

  begin

s:=s+i;

i:=i+1;

end;

writeln(s);

readln;

end.

Bình luận (0)
Thu Tuyền
Xem chi tiết
Minh Lệ
7 tháng 3 2023 lúc 21:23

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.

Bình luận (0)
Nguyễn Hoàng Duy
24 tháng 3 2023 lúc 10:30

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.

Bình luận (0)
Thanh huyền
Xem chi tiết
Minh Lệ
7 tháng 3 2023 lúc 17:08

Đề sai đúng không, bạn kiểm tra lại đề nhé, mình không thấy quy luật gì trong dãy tổng của S cả

Bình luận (1)
Minh Lệ
7 tháng 3 2023 lúc 17:36

FOR..DO

Program HOC24;

var i,n: integer;

s: longint;

begin

write('Nhap N: '); readln(n);

S:=0;

For i:=1 to N do if i mod 2=0 then S:=S+i;

write('S = ',S);

readln

end.

Bình luận (0)
Minh Lệ
7 tháng 3 2023 lúc 23:02

While..do

Program HOC24;

var i,n: integer;

s: longint;

begin

write('Nhap N: '); readln(n);

S:=0; i:=2;

while i<=n do 

begin

s:=s+i;

i:=i+2;

end;

write('S = ',S);

readln

end.

Bình luận (0)