K
Khách

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.

22 tháng 7 2023

program tong_so_le;

var

     n, i, a_i, tong: integer;

begin

     writeln('Nhap vao so nguyen khong am n:');

     readln(n);

     while (n <= 0) or (n > 100) do

     begin

          writeln('So nguyen n phai thoa man 0 < n <= 100, vui long nhap lai:');

          readln(n);

     end;

     writeln('Nhap vao ', n, ' so nguyen a1, a2, ..., an:','<mỗi số nguyên nhập trên một hàng>');

     tong := 0; // Khởi tạo tổng bằng 0

     for i := 1 to n do

     begin

          readln(a_i);

          if i mod 2 = 1 then

               tong := tong + a_i; 

     end;

     writeln('Tong cac so tai vi tri le trong mang la: ', tong);

end.

27 tháng 2 2023

var A:

     array[1..n] of int64;

     i, n, count: integer;

begin

     write('Nhap so phan tu cua mang: ');

     readln(n);

     for i := 1 to n do

     begin

          write('Nhap phan tu thu ', i, ': ');

          readln(A[i]);

      end;

 

     count := 0;

     for i := 1 to n do

          if A[i] > 0 then

               count := count + 1;

     writeln('So luong cac so nguyen duong trong mang la: ', count); end.

9 tháng 7 2022

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll i, j, n, a[1000005], dem = 0, m;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] % 3 == 0)
        {
            n--;
            i--;
        }
    }
    for (i = 1; i <= n; i++)
    {
        cout << a[i] << " ";
    }
    cout<<endl;
    for(i=1;i<=n;i++)
    {
        if(a[i]%5==0)
        {
            for(j=i;j<=n;j++)
            {
                a[j]=a[j+1];
            }
            n--;
            i--;
        }    
    }
    for(i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}

20 tháng 11 2023

def xoa_phan_tu_chia_het_cho_3(arr):
    return [x for x in arr if x % 3 != 0]

# Nhập số phần tử của dãy
n = int(input())

# Nhập dãy số nguyên
day_so = list(map(int, input().split()))

# Xóa các phần tử chia hết cho 3
ket_qua = xoa_phan_tu_chia_het_cho_3(day_so)

# In ra dãy sau khi xóa
print(*ket_qua)

uses crt;

const fi='dulieu.inp';

var f1:text;

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

n,i,t1,t2:integer;

begin

clrscr;

assign(f1,fi); reset(f1);

readln(f1,n);

for i:=1 to n do 

  read(f1,a[i]);

t1:=0;

t2:=0;

for i:=1 to n do 

 begin

if a[i]>0 then t1:=t1+a[i];

if a[i]<0 then t2:=t2+a[i];

end;

writeln('Tong cac so duong la: ',t1);

writeln('Tong cac so am la: ',t2);

close(f1);

readln;

end.

12 tháng 5 2021

program du_lieu;

uses crt;

var i,n:integer;

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

tbc:real;

f:text;

begin

clrscr;

assign(f,'DULIEU.INP');reset(f);

readln(f,n);

for i:=1 to n do

begin

read(f,a[i]);

end;

close(f);

for i:=1 to n do

tbc:=tbc+a[i];

writeln(tbc/n);

readln;

end.

Mình chỉ viết chương trình chính thôi, còn chương trình con bạn tự viết nhé

uses crt;

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

i,n,t,t1,t2:integer;

begin

clrscr;

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

for i:=1 to n do 

 begin

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

edn;

t:=0;

for i:=1 to n do 

 t:=t+a[i];

writeln(t);

readln;

end.

24 tháng 4 2023

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

i,n:integer;

s:longint;

Begin

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

For i:=1 to n do

Begin

Write('Nhap phan tu thu ',i,' = ');readln(a[i]);

s:=s+a[i];

End;

Write('Cac phan tu vua nhap la ');

For i:=1 to n do

Write(a[i]:8);

Writeln;

Write('Tong cua chung la ',s);

Readln

End.

#include <bits/stdc++.h>

using namespace std;

long long a[1000],i,n,t,dem;

int main()

{

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

t=0;

dem=0;

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

if ((a[i]>0) and (i%2==1))

{

t+=a[i];

dem++;

}

cout<<fixed<<setprecision(2)<<(t*1.0)/(dem*1.0);

return 0;

}