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.

26 tháng 2 2020

Program hotrotinhoc;

var x,i,max,n: integer;

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

begin

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

for i:=1 to n do

begin

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

inc(b[a[i]]);

end;

max:=0;

for i:=1 to n do

if b[a[i]]>max then

begin

max:=b[a[i]];

x:=a[i];

end;

write('Phan tu co so lan xuat hien nhieu nhat trong mang la :',x);

readln

end.

#include <iostream> #include <algorithm> using namespace std; int main() { int a[] = { 5,5,5,5,5,4,4,4,4,3,3,3,2,2,1 }; int n = sizeof(a)/sizeof(a[0]); sort(a,a+n); int i = 0, max = 0,index = 0; int frequency; while(i < n) { frequency = 1; while(a[i] == a[i+1]) { frequency++; i++; } if(max < frequency) { max = frequency; index = i; } i++; } cout << "Maximum frequency: " << max << endl; cout << "Element has maximum frequency factor: " << a[index] << endl; return 0; }

Bài 1:

uses crt;
var a:array[1..20]of integer;
i,n,t:integer;
begin
clrscr;
write('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 i mod 2=1 then t:=t+sqr(a[i]);
writeln('tong binh phuong cac phan tu o vi tri le la: ',t);
readln;
end.

uses crt;
var a,b,c,d:array[1..100]of integer;
n,i,dem,t,max,min,j,dem1,kt,dem2,dem3,kt1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Phan tu dau tien la: ',a[1]);
writeln('Phan tu cuoi cung la: ',a[n]);
dem:=0;
for i:=1 to n do
if a[i] mod 4=0 then inc(dem);
writeln('So luong phan tu chia het cho 4 la: ',dem);
t:=0;
for i:=1 to n do
if (a[i] mod 2=0) and (a[i]>10) then t:=t+a[i];
writeln('Tong cac so chan va lon hon 10 la: ',t);
dem1:=0;
for i:=1 to n do
if sqrt(a[i])=trunc(sqrt(a[i])) then
begin
inc(dem1);
b[dem1]:=a[i];
end;
writeln;
writeln('So luong so chinh phuong trong mang la: ',dem1);
if dem1>0 then
begin
writeln('Cac so chinh phuong co trong mang la: ');
for i:=1 to dem1 do
write(b[dem1]:4);
end;
writeln;
kt:=0;
for i:=1 to n do
if a[i] mod 2<>0 then kt:=1;
if kt=0 then writeln('Day la mang chan')
else writeln('Day khong la mang chan');
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;

}

18 tháng 10 2020

uses crt;
var a:array[1..100]of integer;
n,i,t,dem,max,min,kt,j,x,dem1,k: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
t:=t+a[i];
writeln('Tong cac phan tu cua mang la: ',t);
dem:=0;
for i:=1 to n do
if a[i]<0 then inc(dem);
writeln('So phan tu am co trong mang la: ',dem);
max:=a[1];
min:=a[1];
for i:=1 to n do
begin
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
end;
writeln('Tong phan tu nho nhat va lon nhat trong mang la: ',max+min);
writeln('Vi tri cac so nguyen to co trong mang la: ');
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to a[i]-1 do
if a[i] mod j=0 then kt:=1;
if kt=0 then write(i:4);
end;
writeln;
repeat
write('Nhap x='); readln(x);
until x>0;
dem1:=0;
for i:=1 to n do
if a[i]>0 then inc(dem1);
if dem1<x then writeln(x,' nho hon so luong so nguyen duong trong mang')
else if dem1=x then writeln(x,' la so luong so nguyen duong trong mang')
else writeln(x,' lon hon so luong so nguyen duong trong mang');
readln;
end.

8 tháng 12 2019

program hotrotinhoc;

var i,n: byte;

t: longint;

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

begin

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

t:=0;

for i:=1 to n do

begin

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

if (a[i] mod 3=0) and (a[i] mod 5=0) then t:=t+a[i];

end;

writeln('Cac phan tu le trong mang : ');

for i:=1 to n do if a[i] mod 2=1 then write(a[i],' ');

writeln;

write('Tong phan tu chia het cho 3 va 5 la :',t);

readln

end.

uses crt;
var a:array[1..100]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;
{-------------------------xu-ly------------------------}
writeln('cac so le trong day la: ');
for i:=1 to n do
if a[i] mod 2=1 then write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if (a[i] mod 3=0) and (a[i] mod 5=0) then t:=t+a[i];
writeln('tong cac phan tu chia het cho 3 va chia het cho 5 la: ',t);
readln;
end.

22 tháng 11 2019

*Đoạn lệnh :

a.

for i:=1 to n do if a[i]>0 then inc(d);

write(d);

b. t:=0;

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

write(t);

c.

+Vị trí lẻ:

for i:=1 to n do if a[i] mod 2=1 then write(i,' ');

+Vị trí chẵn:

for i:=1 to n do if a[i] mod 2=0 then write(i,' ');

d. max:=0;

for i:=1 to n do if a[i]>max then max:=a[i];

write(max);

e.

for i:=1 to n do

for j:=i to n do

if a[i]<a[j] then

begin

tg:=a[i];

a[i]:=a[j];

a[j]:=tg;

end;

f.

For i:=1 to n do if a[i]=k then write(i,' ');

23 tháng 11 2019

chị @Nguyễn Minh Lệ thì viết một phần gợi ý cho bạn thôi, còn mình sẽ viết hết cả bài cho bạn

uses crt;
var dem2,n,i,dem,t,ln,tam,k,kt,dem1,j:integer;
a,b,vt:array[1..100]of integer;
begin
clrscr;
write('nhap 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]>0 then dem:=dem+1;
writeln('so cac phan tu nguyen duong co trong mang la: ',dem);
{-------------------cau-b-----------------------------}
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('tong cac phan tu chan co trong day la: ',t);
{-------------------cau-c-----------------------------}
writeln('cac so le co trong day la: ');
for i:=1 to n do
if a[i] mod 2=1 then write(a[i]:4);
writeln;
writeln('vi tri cac so le co trong day la: ');
for i:=1 to n do
if a[i] mod 2=1 then write(i:4);
writeln;
{-----------------cau-d--------------------------------}
ln:=a[1];
for i:=1 to n do
if ln<a[i] then ln:=a[i];
writeln('so lon nhat co trong day la: ',ln);
{----------------cau-e--------------------------------}
b[1]:=a[1];
dem1:=0;
for i:=1 to n do
begin
dem1:=dem1+1;
b[dem1]:=a[i];
end;
writeln('day tang dan cua A 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-f-------------------------}
writeln;
write('nhap so k: '); readln(k);
kt:=0;
dem2:=0;
for i:=1 to dem1 do
if b[i]=k then
begin
kt:=1;
dem2:=dem2+1;
vt[dem2]:=i;
end;
if kt=0 then writeln(k,' khong co trong day')
else begin
writeln(k,' co trong day A tai cac vi tri lan luot la: ');
for i:=1 to dem2 do
write(vt[i]:4);
end;
readln;
end.

uses crt;

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

i,n,dem:integer;

begin

clrscr;

repeat

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

until (1<=n) and (n<=1000);

for i:=1 to n do 

  begin

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

end;

writeln('Mang ban vua nhap la: ');

for i:=1 to n do 

  write(a[i]:4);

writeln;

dem:=0;

for i:=1 to n do 

  if a[i] mod 3=0 then inc(dem);

writeln('So phan tu chia het cho 3 la: ',dem);

readln;

end.

18 tháng 10 2020

Bài 1:

uses crt;
var a,b:array[1..100]of integer;
i,n,dem,t,dem1,max,tam,j,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
for i:=1 to n do
if a[i] mod 2<>0 then inc(dem);
writeln('So luong so le la: ',dem);
t:=0;
for i:=1 to n do
if a[i] mod 5=0 then t:=t+a[i];
writeln('Tong cac phan tu chia het cho 5 la: ',t);
dem1:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
inc(dem1);
b[dem1]:=a[i];
end;
max:=b[1];
for i:=1 to dem1 do
if max<b[i] then max:=b[i];
writeln('Phan tu chan lon nhat la: ',max);
writeln('Vi tri cua no trong mang la: ');
for i:=1 to n do
if max=a[i] then write(i:4);
writeln;
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;
writeln('Mang duoc sap xep tang dan la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
writeln('Cac so nguyen to trong day la: ');
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to a[i]-1 do
if a[i] mod j=0 then kt:=1;
if kt=0 then write(a[i]:4);
end;
readln;
end.