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?
Bài 1:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i;
inc(i);
end;
writeln('Tong cac so trong khoang tu 1 den ',n,' la: ',s);
readln;
end.
Bài 2:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i;
i:=i+2;
end;
writeln('Tong cac so le trong khoang tu 1 den ',n,' la: ',s);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long n,i,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
if (i%2==0) t+=i;
cout<<t;
return 0;
}
Cách 1 dùng lệnh for do:
Uses crt;
var i,n,k: integer;
begin clrcsr;
readln(n);
for i:=1 to n do begin
if(i mod 2=0) and (i>=10) then k:=k*i;
end;
writeln(k);
readln;
end.
Cách 2 dùng lệnh while do
Uses crt;
var m,n,o: integer;
begin clrcsr;
readln(n);
o:=1;
m:=1;
while (m<n) do begin
m:=m+1;
if(m mod 2=0) and (m>=10) then o:=o*m;
end;
writeln(o);
readln;
end.
program tim_uoc;
uses crt;
var i,n,tong:integer;
begin
clrscr;
write('nhap so n:');readln(n);
i:=1;tong:=0;
writeln('cac uoc cua ',n,' la:');
while i<=n do
if n mod i=0 then
begin
write(i:3);
inc(i);
end;
writeln;
i:=1;writeln('cac uoc chan:');
while i<=n do
begin
if n mod i=0 then
begin
if i mod 2=0 then write(i:3);
tong:=tong+i;
end;
end;
writeln;
write('tong cac uoc chan:',tong);
readln;
end.
uses crt;
var n,i,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
i:=1;
writeln('Cac uoc cua ',n,' la: ');
while i<=n do
begin
if n mod i=0 then write(i:4):
i:=i+1;
end;
writeln;
writeln('Cac uoc chan cua ',n,' la: ');
t:=0;
i:=1;
while i<=n do
begin
if (n mod i=0) then
begin
t:=t+i;
write(i:4);
end;
inc(i);
end;
writeln('Tong cac uoc chan cua ',n,' la: ',t);
readln;
end.
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.
Uses Crt;
Var A : array [1..1000] of longint;
n, m, d, t, i, S, k : longint;
Begin
//Phan A
Clrscr;
Writeln(' Phan A ');
Write(' Ban hay nhap 1 so n bat ky: ');
Readln(n);
Write(' Cac so chia het cho ba tu 1 den ',n,' la: ');
For i:=1 to n do
If (i mod 3) = 0 then Write(' ',i);
//Phan B
Writeln;
Writeln(' Phan B ');
Write(' Ban hay nhap 1 so m bat ky: ');
Readln(m);
For i:=1 to m do
Begin
Write(' Ban hay nhap hang tu thu ',i,': ');
Readln(A[i]);
S:= S+A[i];
End;
Write(' Tong cua day so tren la: ',S);
//Phan C
Writeln;
Writeln(' Phan C ');
Write(' Ban hay nhap 1 so d bat ky: ');
Readln(d);
Write(' Ban hay nhap so K: ');
Readln(k);
For i:=1 to n do
Begin
Write(' Ban hay nhap hang tu thu ',i,': ');
Readln(A[i]);
If ((A[i] div k)=1)then t:=t+1;
End;
Write(' Co tat ca ',t,' so giong ',k);
Readln;
End.
Program HOC24;
var i,n,t: integer;
begin
write('Nhap N: '); readln(n);
i:=2; t:=0;
while i<=n do
begin
t:=t+i;
i:=i+2;
end;
write('Tong cac so chan tu 1 den ',n,' la: ',t);
readln
end.