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.
#include <bits/stdc++.h>
using namespace std;
long long s,i,n;
int main()
{
cin>>n;
s=1;
for (i=1; i<=n; i++)
if (i%2==0) s=s+i;
cout<<s;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long i,n;
double s;
int main()
{
cin>>n;
s=0;
for (i=1; i<=n; i++)
s=s+1/(i*1.0);
cout<<fixed<<setprecision(2)<<s;
return 0;
}
Program HOC24;
var n,i: integer;
s: longint;
begin
write('Nhap N: '); readln(n);
s:=2021;
for i:=0 to n do s=s+(2*i+1);
write('S= ',s);
readln
end.
*Cách 2: Dùng While do
uses crt;
var s,i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=2021;
i:=0;
while i<=n do
begin
s:=s+(2*i+1);
i:=i+1;
end;
writeln(s);
readln;
end.
Program bt_3;
Uses crt;
Var Tong, n, i: integer;
Begin
Clrscr;
Writeln(‘nhap n=’);
Readln (n);
Tong:=0;
For i:=1 to n do
If I mod 5 = 0 then Tong:= Tong+i;
Writeln(‘Tong la:’,Tong);
Readln
End.
Câu 1:
uses crt;
var a:array[1..500]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if (a[i]<0) and (a[i] mod 7=0) then t:=t+a[i];
writeln('Tong cac so am chia het cho 7 la: ',t);
readln;
end.
Câu 2:
uses crt;
var c,a:array[1..10]of integer;
i,kt,j,dem:integer;
begin
clrscr;
for i:=1 to 10 do
begin
write('C[',i,']='); readln(c[i]);
end;
dem:=0;
for i:=1 to 10 do
if c[i]>1 then
begin
kt:=0;
for j:=2 to c[i]-1 do
if c[i] mod j=0 then kt:=1;
if kt=0 then
begin
inc(dem);
a[dem]:=c[i];
end;
end;
if dem=0 then writeln('Trong day khong co so nguyen to')
else begin
writeln('Cac so nguyen to trong day la: ');
for i:=1 to dem do
write(a[i]:4);
end;
readln;
end.
Câu 3:
uses crt;
var d:array[1..200]of integer;
i,k,dem:integer;
begin
clrscr;
write('Nhap k='); readln(k);
for i:=1 to k do
begin
write('D[',i,']='); readln(d[i]);
end;
dem:=0;
for i:=1 to k do
if (a[i] mod 2=0) and (a[i]>=10) then inc(dem);
writeln('So phan tu chan co 2 chu so la: ',dem);
readln;
end.
Program bt_3;
Uses crt;
Var Tong, n, i: integer;
Begin
Clrscr;
Writeln(‘nhap n=’);
Readln (n);
Tong:=0;
For i:=1 to n do
If I mod 3 = 0 then Tong:=Tong+i;
Writeln(‘Tong la:’,Tong);
Readln
End.
Bài 1:
function canbac2(x:longint):real;
begin
canbac2:=sqrt(x);
end;
Bài 2:
function tong(n:longint):longint;
var s,i:longint;
begin
s:=0;
for i:=1 to n do
s:=s+i;
tong:=s;
end;
Program bt_3;
Uses crt;
Var Tong, n, i: integer;
Begin
Clrscr;
Writeln(‘nhap n=’);
Readln (n);
Tong:=0;
For i:=1 to n do
If I mod 2 = 1 then Tong:= Tong+i;
Writeln(‘Tong la:’,Tong);
Readln
End.