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.
n = int(input("Nhap n: "))
sum_even = 0
for i in range(2, n+1, 2):
sum_even += i
print("Tong cac so chan lien tiep den", n, "la:", sum_even)
python ha:0?
uses crt;
var i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
i:=1;
t:=0;
while i<=n do
begin
if i mod 2=0 then t:=t+i;
i:=i+1;
end;
write(t);
readln;
end.
Program viet_chuong_trinh_tinh_tong;
Uses Crt;
Var i,s:integer;
Begin
Clrscr;
i:=2;
While (i>1) and (i<=100) do
Begin
s:=s+i;
i:=i+2;
End;
Writeln(S);
Readln;
End.
uses crt;
var i:integer;
begin
clrscr;
i:=50;
while i<=150 do
begin
if i mod 2=0 then write(i:4);
i:=i+1;
end;
writeln;
i:=50;
while i<=150 do
begin
if i mod 2=1 then write(i:4);
i:=i+1;
end;
readln;
end.
Câu 2:
uses crt;
var a:array[1..100]of integer;
i,n,tb:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
tb:=0;
for i:=1 to n do
tb:=tb+a[i];
writeln(tb/n:4:2);
readln;
end.
a)
program TenCuaMinh;
var
i: integer;
begin
for i := 1 to 10 do
writeln('Tên của mình là: <tên>');
end.
b)
program MangSoNguyen;
var
M: array[1..100] of integer;
begin
end.
uses crt;
var a:array[1..100]of integer;
i:integer;
begin
clrscr;
for i:=1 to 100 do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to 100 do
write(a[i]:2);
readln;
end.
program timtich;
uses crt;
var i,n:integer;
tich:longint;
a:array[1..100]of integer;
begin
clrscr;
write('nhap so n:');readln(n);
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
for i:=1 to n do
write(a[i]:4);
tich:=1;
writeln;
for i:=1 to n do
if a[i] mod 2=0 then tich:=tich*a[i];
writeln('tich ca phan tu chan cua mang la:',tich);
readln;
end.
program timtong;
uses crt;
var i,n:integer;
tong:longint;
a:array[1..100]of integer;
begin
clrscr;
write('nhap so n:');readln(n);
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
for i:=1 to n do
write(a[i]:4);
tong:=0;
writeln;
for i:=1 to n do
if a[i] mod 2=0 then tong:=tong+a[i];
writeln('tong cac phan tu chan cua mang la:',tong);
tong:=0;
writeln;
for i:=1 to n do
if a[i] mod 2=1 then tong:=tong+a[i];
writeln('tong cac phan tu le cua mang la:',tong);
readln;
end.
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
s:=1;
for i:=1 to n do
if a[i] mod 2=0 then s:=s*a[i];
writeln(s);
readln;
end.
program TongChanLe;
var
n,i, chans, les: integer; a: array[1..100] of integer;
begin
chans := 0;
les := 0;
write('Nhap n: ');
readln(n);
for i:=1 to n do
begin
write('Nhap so thu ', i, ': ');
readln(a[i]);
if a[i] mod 2 = 0 then
chans := chans + a[i]
else
les := les + a[i];
end;
writeln('Tong cac so chan la: ', chans);
writeln('Tong cac so le la: ', les);
readln;
end.
program cach1;
var i:integer
begin
for i:=1 to 100 do write(i*2);
readln
end.
program cach2;
var i:integer;
begin
for i:=1 to 100 do if i mod 2=0 then write(i);
readln
end.
program ct1;
uses crt;
var i:integer;
begin
write (' Cac so chan trong day so la: ');
for i:=1 to 100 do if i mod 2=0 then write (i:3);
readln;
end.
- Thử xem nhé!