Những câu hỏi liên quan
Jhon wisk
Xem chi tiết
Nguyễn An Ninh
25 tháng 4 2023 lúc 10:01

#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n,dem=0,s=0;
    cin >> n;
    for (long long i=1;i<=n;i+=2){
        dem++;
        s+=i;
    }
    cout << "tu 0 den n co: " << dem << " so le" << endl;
    cout << "tong cac so le do la: " << s;
    return 0;

Bình luận (0)
Phan Thị Ka
Xem chi tiết
Minh Lệ
19 tháng 3 2023 lúc 22:40

Câu 1:

Program HOC24;

var i,p: integer;

t: longint;

begin

write('Nhap P: '); readln(p);

t:=0;

for i:=1 to p do if i mod 2<>0 then t:=t+i;

write('Tong cac so le la: ',t);

readln

end.

Bình luận (0)
Minh Lệ
19 tháng 3 2023 lúc 22:41

Câu 2:

Program HOC24;

var i,n: integer;

t: longint;

begin

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

t:=0;

for i:=1 to n do if i mod 2=0 then t:=t+i;

write('Tong cac so chan la: ',t);

readln

end.

Bình luận (0)
Minh Lệ
19 tháng 3 2023 lúc 22:42

Câu 3:

Program HOC24;

var i,t,n: integer;

begin

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

t:=0;

for i:=1 to n do if n mod i=0 then t:=t+i;

write('Tong cac uoc cua ',n,' la: ',t);

readln

end.

Bình luận (0)
Nguyễn Đức Hòa
Xem chi tiết
Nguyễn Lê Phước Thịnh
21 tháng 1 2022 lúc 21:55

uses crt;

var t,n,i,dem:integer;

begin

clrscr;

readln(n);

dem:=0;

t:=0;

for i:=0 to n do 

  if i mod 2=0 then 

begin

t:=t+i;

dem:=dem+1;

end;

writeln(dem,' ',t);

readln;

end.

Bình luận (0)
Tuoi tom May
Xem chi tiết
Aurora Maleine
Xem chi tiết
Nguyễn Lê Phước Thịnh
1 tháng 3 2022 lúc 22:57

uses crt;

var i,n,t:integer;

begin

clrscr;

readln(n);

t:=0;

for i:=1 to n do if i mod 2=1 then t:=t+i;

writeln(t);

readln;

end.

Bình luận (0)
Yna Lolipop
Xem chi tiết
Nguyễn Lê Phước Thịnh
2 tháng 3 2022 lúc 23:11

1:

#include <bits/stdc++.h>

using namespace std;

long long dem,i,n,x;

int main()

{

cin>>n;

dem=0;

for (i=1; i<=n; i++)

{

cin>>x;

if (x%2==0) dem++;

}

cout<<dem;

return 0;

}

Câu 2: 

#include <bits/stdc++.h>

using namespace std;

long long x,n,i,t;

int main()

{

cin>>n;

t=0;

for (i=1; i<=n; i++)

{

cin>>x;

if (x%3==0) t+=x;

}

cout<<t;

return 0;

}

Bình luận (0)
Huy Đại Ca
Xem chi tiết
Huy Đại Ca
5 tháng 5 2021 lúc 14:47

Viết chương trình nhập vào số nguyên n và tính tổng các số lẻ (các số lẻ là số không chia hết cho 2) trong khoảng từ 1 đến n ( ví dụ nhập = 10, ta sẽ có tổng sau s=1+3+5+7+9=25)

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

uses crt;

var i,n,s:integer;

begin

clrscr;

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

s:=0;

for i:=1 to n do 

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

writeln(s);

readln;

end.

Bình luận (0)
Sarah Lilia
Xem chi tiết
Nguyễn Lê Phước Thịnh
17 tháng 2 2021 lúc 20:53

uses crt;

var a:array[1..100]of integer;

i,n,dem,dem1,dem2,t:integer;

s:real;

begin

clrscr;

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

for i:=1 to n do 

begin

repeat

write('A[',i,']='); readln(a[i]);

until a[i]>0;

end;

for i:=1 to n do 

  write(a[i]:4);

writeln;

dem:=0;

for i:=1 to n do

  if a[i]>10 then inc(dem);

writeln('So phan tu lon hon 10 la: ',dem);

dem1:=0;

dem2:=0;

for i:=1 to n do 

begin

if a[i] mod 2=0 then inc(dem1)

else inc(dem2);

end;

writeln('So luong so chan la: ',dem1);

writeln('So luong so le la: ',dem2);

t:=0;

s:=1;

for i:=1 to n do 

  begin

if (i mod 2=0) and (a[i] mod 2<>1) then t:=t+a[i];

if (i mod 2=1) and (a[i] mod 2=0) then s:=s*a[i];

end;

writeln('Tong cac so o vi tri chan co gia tri le la: ',t);

writeln('Tich cac so o vi tri le co gia tri chan la: ',s:4:2);

writeln('Cac so le la: ');

for i:=1 to n do 

  if a[i] mod 2<>0 then write(a[i]:4);

writeln;

writeln('Cac so chan va lon hon 10 la: ');

for i:=1 to n do 

  if (a[i] mod 2=0) and (a[i]>10) then write(a[i]:4);

readln;

end.

Bình luận (1)
Lê Thế Phong
Xem chi tiết
Lê Thế Phong
21 tháng 1 2022 lúc 16:09

giúp với

 

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

#include <bits/stdc++.h>

using namespace std;

string st;

int d,i,dem;

int main()

{

cin>>st;

d=st.length();

dem=0;

for (i=0; i<d; i++)

if (st[i]=='0') dem++;

cout<<dem;

return 0;

}

Bình luận (0)
Kiều Vũ Linh
22 tháng 1 2022 lúc 8:33

Var n,dem:longint;

Begin

Write('Nhap so n = ');readln(n);

While n >= 10 do

Begin

if n mod 10 = 0 then dem:=dem+1;

n:=n div 10;

End;

Write('So vua nhap co ',dem,' so 0');

Readln;

End.

Bình luận (0)