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 a:array[1..20]of integer;
i,n,t,dem:integer;
begin
clrscr;
for i:=1 to 20 do
begin
repeat
write('A[',i,']='); readln(a[i]);
until a[i]>0;
end;
t:=0;
for i:=1 to 20 do
t:=t+a[i];
writeln('Tong cac so trong mang la: ',t);
dem:=0;
for i:=1 to 20 do
if a[i] mod 2=0 then inc(dem);
writeln('Trong mang co ',dem,' so chan');
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long n,i,a[10000];
int main()
{
cin>>n;
for (i=1; i<=n; i++)
cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
return 0;
}
tham khảo'
uses crt;
var a:array[1..100]of integer;
i,n,t,dem:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
t:=t+a[i];
inc(dem);
end;
writeln('Tong cac so chan la: ',t);
writeln('So luong so chan la: ',dem);
readln;
end.
Var a:array[1..100] of integer;
i,n,dem,vt,s sc,sl,min:integer;
tbc:real;
Begin
Write('Nhap so luong phan tu n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap phan tu thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do s:=s+a[i];
tbc:=s/n;
Writeln('Gia tri trung binh cua mang la ',tbc:10:2);
Write('Cac phan tu lon hon gia tri trung binh la ');
For i:=1 to n do
If a[i]>tbc then write(a[i],' ');
For i:=1 to n do
Begin
If a[i] mod 2 = 0 then sc:=sc+a[i]
Else sl:=sl+a[i];
End;
Writeln('Tong cac phan tu chan la ',sc);
Writeln('Tong cac phan tu le la ',sl);
min:=a[1];
For i:=2 to n do
Begin
If a[i] < min then min:=a[i];
vt:=i;
End;
Writeln('Phan tu nho nhat la ',min,' tai vi tri ',vt);
For i:=1 to n do
If a[i] mod 5 = 0 then dem:=dem+1;
Write('So cac phan tu chia het cho 5 la ',dem);
Readln;
End.
Đề bài 1:
uses crt;
var a,b,c:array[1..100]of integer;
k,i,n,max,min,dem,dem1,tam,j,dem2,t:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
write('nhap k='); readln(k);
{-------------------------------cau-a--------------------------}
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('gia tri lon nhat cua mang la: ',max);
dem:=0;
for i:=1 to n do
if max=a[i] then
begin
inc(dem);
b[dem]:=i;
end;
writeln('vi tri cua no lan luot la:');
for i:=1 to dem do
write(b[i]:4);
{-----------------------------cau-b--------------------------}
writeln;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('gia tri nho nhat cua mang la: ',min);
dem1:=0;
for i:=1 to n do
if min=a[i] then
begin
inc(dem1);
c[dem1]:=i;
end;
writeln('vi tri cua no lan luot la:');
for i:=1 to dem1 do
write(c[i]:4);
{--------------------------cau-c------------------------}
writeln;
t:=0;
for i:=1 to n do
if i mod 2=0 then t:=t+sqr(a[i]);
writeln('tong binh phuong cac phan tu o vi tri chan la: ',t);
{------------------------cau-d-------------------------------}
writeln('mang duoc sap xep tang dan la: ');
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
for i:=1 to n do
write(a[i]:4);
{------------------------cau-e-----------------------}
writeln;
dem2:=0;
for i:=1 to n do
if a[i]=k then inc(dem2);
writeln('so gia tri bang ',k,' trong day la: ',dem2);
readln;
end.
Đề bài 2:
uses crt;
var a:array[1..100]of integer;
n,i,dem,dem1,t,t1,t2:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------------------cau-a--------------------------}
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln('so luong so chan co trong mang la: ',dem);
{-------------------------------cau-b---------------------------}
dem1:=0;
for i:=1 to n do
if a[i] mod 2<>0 then inc(dem1);
writeln('so luong so le co trong mang la: ',dem1);
{-----------------------------cau-c--------------------------}
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('tong cac so chan co trong mang la: ',t);
{------------------------------cau-d--------------------------}
t1:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t1:=t1+a[i];
writeln('tong cac so le co trong mang la: ',t1);
{------------------------------cau-e-------------------------}
t2:=0;
for i:=1 to n do
t2:=t2+a[i];
writeln('gia tri trung binh cua mang la: ',t2/n:4:2);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,dem,t,j,t1;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
dem=0;
for (i=1; i<=n; i++)
{
t=0;
for (j=1; j<=a[i]-1; j++)
if (a[i]%j==0) t+=j;
if (t==a[i]) dem++;
}
cout<<dem<<endl;
t1=0;
for (i=1; i<=n; i++)
if (a[i]%2==0) t1+=a[i];
cout<<t1;
return 0;
}