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.
* Sử dụng For ... do
Var i,s:integer;
Begin
For i:=1 to 10 do
s:=s+i;
Write('Tong la ',s);
Readln;
End.
* Sử dụng While ... do
Var i,s:integer;
Begin
i:=1;
While i<=10 do
Begin
s:=s+i;
i:=i+1;
End;
Write('tong la ',s);
Readln;
End.
uses crt;
var i,n,t:integer;
begin
clrscr;
readln(n);
t:=0;
i:=0;
while i<=n do
begin
i:=i+1;
if i mod 2=0 then t:=t+i;
end;
writeln(t);
readln;
end.
uses crt;
var i,t:integer;
begin
clrscr;
t:=0;
for i:=1 to 100 do t:=t+i;
writeln(t);
readln;
end.
uses crt;
var i,t:integer;
begin
clrscr;
t:=0;
for i:=1 to 100 do t:=t+i;
writeln(t);
readln;
end.
Tham khảo theo link nhé bạn: https://hoc24.vn/hoi-dap/tim-kiem?id=603125&q=t%C3%ADnh%20t%E1%BB%95ng%20c%C3%A1c%20s%E1%BB%91%20t%E1%BB%B1%20nhi%C3%AAn%20t%E1%BB%AB%20100%20%C4%91%E1%BA%BFn%201000%20%28v%C3%B2ng%20l%E1%BA%B7p%20v%E1%BB%9Bi%20s%E1%BB%91%20l%E1%BA%B7p%20ch%C6%B0a%20bi%E1%BA%BFt%29
uses crt;
var n,i,t,x:integer;
begin
clrscr;
readln(n);
t:=0;
while n>0 do
begin
x:=n mod 10;
if x mod 2=0 then t:=t+x;
n:=n div 10;
end;
writeln(t);
readln;
end.
câu 1:
uses crt;
var p,i:integer;
begin
clrscr;
p:=1;i:=1;while i<=5 do
begin
p:=p*i;i:=i+1;
end;
write(p);
readln;
end.
bai 2:
uses crt;var p,i:integer;begin clrscr; p:=1; i:=0; while i <=10 do begin
i:=i+1; if (i mod 2<>0) then p:=p*i; end; write(p); readln;end. bai 3:
uses crt;var n,i,p:integer;begin clrscr; write('nhap n: '); readln(n); i:=1; p:=1; while i<=n do begin if i mod 2=0 then p:=p*i; i:=i+1; end; write(p); readln;end.
program TinhTongTich;
var
N, i, Tong, Tich:integer;
begin
writeln('Nhap so nguyen duong N:');
readln(N);
i:=1;
Tong:=0;
Tich:=1;
while i<=N do
begin
Tong:=Tong+i;
Tich:=Tich*i;
i:=i+1;
end;
writeln('Tong cac so tu 1 den ', N, ' la: ', Tong);
writeln('Tich cac so tu 1 den ', N, ' la: ', Tich);
readln;
end.
Sử dụng For.. do:
Var i,S:integer;
Begin
For i:= 1 to 100 do If i mod 2 = 0 then S:= S+i;
Writeln(' tong cac so chan :',S);
Readln;
end.
Sử dụng While ..do:
Var i,S:integer;
Begin
i:=0;
While i<=100 do If i mod 2 = 0 then S:= S+i;
Writeln(' tong cac so chan :',S);
Readln;
end.