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.

uses crt;
var n,i,t,dem,t1,dem1,t2:longint;
a:array[1..100]of longint;
tbc,tbca,tbcd:real;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{--------------------cau-1-----------------------}
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('tong cac phan tu cua day la: ',t);
{-------------------cau-2-------------------------}
dem:=0;
t1:=0;
for i:=1 to n do
if a[i]>0 then
begin
dem:=dem+1;
t1:=t1+a[i];
end;
writeln('so luong cac so hang duong la: ',dem);
writeln('tong cua cac so hang duong la: ',t1);
{-------------------cau-3-------------------------}
dem1:=0;
t2:=0;
for i:=1 to n do
if a[i]<0 then
begin
inc(dem1);
t2:=t2+a[i];
end;
writeln('so luong cac so hang am la: ',dem1);
writeln('tong cua cac so hang am la: ',t2);
{-------------------cau-4-----------------------}
tbc:=t/n;
writeln('trung binh cong cua day so la: ',tbc:4:2);
tbcd:=t1/dem;
writeln('trung binh cong cua cac phan tu duong la: ',tbcd:4:2);
tbca:=t2/dem1;
writeln('trung binh cong cua cac phan tu am la: ',tbca:4:2);
readln;
end.

18 tháng 3 2020

program an_danh;
uses crt;
var n,i,nd,na:integer;
tbc,tbcd,tbca:real;
tong,tongd,tonga:longint;
a:array [1..10] of integer;
begin
clrscr;
write('So phan tu cua day so: ');readln(n);
for i:= 1 to n do
begin
write('Phan tu thu ',i,': ');
readln(a[i]);
end;
tong:= 0;
for i:= 1 to n do tong:= tong + a[i];
tbc:= tong / n;
writeln('Tong cac phan tu la: ',tong);
nd:= 0; tongd:= 0;
for i:= 1 to n do
if a[i] mod 2 = 0 then
begin
nd:= nd + 1;
tongd:= tongd + a[i];
end;
tbcd:= tongd / nd;
writeln('So cac phan tu duong trong day: ',nd);
writeln('Tong cac phan tu duong trong day: ',tongd);
na:= 0; tonga:= 0;
for i:= 1 to n do
if a[i] mod 2 <> 0 then
begin
na:= na + 1;
tonga:= tonga + a[i];
end;
tbca:= tonga / na;
writeln('So cac phan tu am trong day: ',na);
writeln('Tong cac phan tu am trong day: ',tonga);
writeln('Trung binh cong cua ca day: ',tbc:0:2);
writeln('Trung binh cong cac phan tu duong: ',tbcd:0:2);
write('Trung binh cong cac phan tu am: ',tbca:0:2);
readln
end.

uses crt;
var i,n,tcd,t,t1,dem,dem1,dem2,dem3,dem4,dem5:longint;
a,b,c:array[1..100]of longint;
min,max:int64;
tbc,tbcd,tbca:real;
begin
clrscr;
write('nhap n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{---------------------------cau-1----------------------}
tcd:=0;
for i:=1 to n do
tcd:=tcd+a[i];
writeln('tong cac phan tu trong day la: ',tcd);
{-------------------------cau-2----------------------}
dem:=0;
t:=0;
for i:=1 to n do
if a[i]>0 then
begin
inc(dem);
t:=t+a[i];
end;
writeln('so luong cac so hang duong la: ',dem);
writeln('tong cac so hang duong la: ',t);
{-----------------------cau-3-----------------------}
dem1:=0;
t1:=0;
for i:=1 to n do
if a[i]<0 then
begin
inc(dem1);
t1:=t1+a[i];
end;
writeln('so luong cac so hang am la: ',dem1);
writeln('tong cac so hang am la: ',t1);
{---------------------cau-4---------------------------}
tbc:=tcd/n;
tbcd:=t/dem;
tbca:=t1/dem1;
writeln('trung binh cong cua ca day la: ',tbc:4:2);
writeln('trung binh cong cua cac so duong la: ',tbcd:4:2);
writeln('trung binh cong cua cac so am la: ',tbca:4:2);
{--------------------cau-5--------------------------------}
max:=0;
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('so lon nhat cua day la: ',max);
writeln('chi so cua no la: ');
dem2:=0;
for i:=1 to n do
if max=a[i] then
begin
inc(dem2);
b[dem2]:=i;
end;
for i:=1 to dem2 do
write(b[i]:4);
{---------------------cau-6-----------------------------}
writeln;
min:=maxint;
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('so nho nhat cua day la: ',min);
writeln('chi so cua no la: ');
dem3:=0;
for i:=1 to n do
if min=a[i] then
begin
inc(dem3);
c[dem3]:=i;
end;
for i:=1 to dem3 do
write(c[i]:4);
{-------------------------cau-7------------------------}
writeln;
dem4:=0;
dem5:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then inc(dem4);
if a[i] mod 2=1 then inc(dem5);
end;
writeln('so luong so chan cua day la: ',dem4);
writeln('so luong so le cua day la: ',dem5);
readln;
end.

26 tháng 2 2023

# Nhap mang

arr = [ ]

for i in range(10):

     arr.append(int(input('Nhap phan tu: ')))

 

# Tinh va xuat ra tong cac phan tu le trong mang tong_cac_phan_tu_le = 0

for x in arr:

     if x % 2 != 0:

          tong_cac_phan_tu_le += x

print('Tong cac phan tu le trong mang la:', tong_cac_phan_tu_le)

 

# Nen va xuat ra ngoai man hinh so phan tu duong trong mang so_phan_tu_duong = 0

for x in arr:

     if x > 0:

          so_phan_tu_duong += 1

print('So phan tu duong trong mang la:', so_phan_tu_duong)

 

# Tinh va xuat ra man hinh trung binh cong cac phan tu trong mang tong_phan_tu = 0

for x in arr:

          tong_phan_tu += x

trung_binh_cong = tong_phan_tu / len(arr)

print('Trung binh cong cac phan tu trong mang la:',trung_binh_cong)

 

# Tim va xuat ra man hinh gia tri va vi tri cua cac phan tu nho nhat trong mang

min_phan_tu = arr[0]

vi_tri_min_phan_tu = 0

for i in range(1, len(arr)):

     if min_phan_tu > arr[i]:

          min_phan_tu = arr[i]

           vi_tri_min_phan_tu = i

print('Gia tri cua phan tu nho nhat trong mang la:', min_phan_tu)

print('Vi tri cua phan tu nho nhat trong mang la:', vi_tri_min_phan_tu)

      

b: #include <bits/stdc++.h>

using namespace std;

long long b[1000],i,n;

int main()

{

cin>>n;

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

cin>>b[i];

sort(b+1,b+n+1);

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

cout<<b[i]<<" ";

return 0;

}

Câu 7:

const fi='dayso.inp';

fo='dayso.out';

var f1,f2:text;

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

i,n,dem,j,t,kt,dem1:integer;

begin

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

assign(f2,fo); rewrite(f2);

readln(f1,n);

for i:=1 to n do 

  read(f1,a[i]);

t:=0;

for i:=1 to n do 

  t:=t+a[i];

writeln(f2,'Tong cua day so la: ',t);

b[1]:=a[1];

dem:=1;

for i:=1 to n do 

  begin

kt:=0;

for j:=1 to dem do 

  if a[i]=b[j] then kt:=1;

if kt=0 then

begin

inc(dem);

b[dem]:=a[i];

end;

end;

for i:=1 to dem do 

  begin

dem1:=0;

for j:=1 to n do 

  if b[i]=a[j] then inc(dem1);

writeln(f2,b[i],' xuat hien ',dem1,' lan');

close(f1);

close(f2);

end.

Bài 1:

#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<0) and (x%2!=0)) t=t+x;

}

cout<<t;

return 0;

}

Bai 2:

uses crt;

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

i,n,t,nn:integer;

begin

clrscr;

readln(n);

for i:=1 to n do readln(a[i]);

nn:=a[1];

for i:=1 to n do

if nn>a[i] then nn:=a[i];

write(nn);

readln;

end.

uses crt;

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

i,t:integer;

begin

for i:=1 to 10 do 

  begin

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

end;

t:=0;

for i:=1 to 10 do 

  t:=t+a[i];

writeln('Tong cua day la: ',t);

writeln('Trung binh cong cua day la: ',t/n:4:2);

readln;

end.