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.
#include <bits/stdc++.h>
using namespace std;
long long b[15],i,n,k,dem;
bool kt;
int main()
{
n=15;
for (i=1; i<=n; i++) cin>>b[i];
for (i=1; i<=n; i++) cout<<b[i]<<" ";
cout<<endl;
dem=0;
for (i=1; i<=n; i++) if (b[i]%2==0) dem++;
cout<<"So so chan la: "<<dem<<endl;
cin>>k;
kt=false;
for (i=1; i<=n; i++) if (b[i]==k)
{
cout<<i<<" ";
kt=true;
}
if (kt==false) cout<<"Khong co k trong day";
else cout<<endl;
sort(b+1,b+n+1);
for (i=1; i<=n; i++) cout<<b[i]<<" ";
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,dem,t,tb:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
t:=0;
for i:=1 to n do
if a[i]>0 then
begin
dem:=dem+1;
t:=t+a[i];
end;
writeln('So luong phan tu duong la: ',dem);
writeln('Tong cac phan tu duong la: ',t);
writeln('Trung binh cac phan tu duong la: ',t/dem:4:2);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
cout<<"Cac so duong la: ";
for (i=1; i<=n; i++) if (a[i]>0) cout<<a[i]<<" ";
cout<<endl;
for (i=1; i<=n; i++) if (a[i]%2==0) cout<<a[i]<<" ";
for (i=1; i<=n; i++) if (a[i]%2!=0) cout<<a[i]<<" ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i;
int main()
{
cin>>n;
for (i=1;i<=n; i++) cin>>a[i];
for (i=1;i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
for (i=1; i<=n; i++)
if (a[i]%2==0 && a[i]<0) cout<<a[i]<<" ";
cout<<endl;
for (i=1; i<=n; i++)
if (a[i]>0) cout<<a[i]<<" ";
for (i=1; i<=n; i++)
if (a[i]==0) cout<<a[i]<<" ";
for (i=1; i<=n; i++)
if (a[i]<0) cout<<a[i]<<" ";
return 0;
}
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n,kt,max,x,j,tam:integer;
begin
clrscr;
write('Nhap n='); readln(n);
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;
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('Day tang dan la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
write('Nhap x='); readln(x);
max:=0;
kt:=0;
for i:=1 to n do
if (a[i] mod 2=0) and (a[i]<=x) then
begin
if max<a[i] then max:=a[i];
kt:=1;
end;
if kt=0 then writeln('Trong day khong co so le')
else writeln('So chan lon nhat khong vuot qua ',x,' la: ',max);
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.
program so_lon_nhat;
uses crt;
var a: array[1..100] of integer;
i,n,max,k,dem: integer;
s,tbc: real;
begin
clrscr;
writeln(' nhap so phan tu cua day'); readln(n);
for i:=1 to n do
begin
writeln('a[',i,']'); readln(a[i]);
end;
writeln(' nhap so can tim:'); readln(k);
max:=a[1];
i:=1;
dem:=0;
for i:=1 to n do
begin
if max<a[i] then max:=a[i];
s:=s+a[i];
tbc:=s/n;
if a[i]=k then dem:=dem+1;
end;
writeln(' so lon nhat trong day tren la:',max);
while (i<n) and (a[i]<>k) do i:=i+1;
if a[i]=k then writeln(' phan tu thu ', i ,' bang ',k)
else writeln(' k tim dc phan tu',k);
writeln(tbc:6);
writeln('co', dem, ' phan tu', k);
readln
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,dem;
int main()
{
cin>>n;
for(i=1; i<=n; i++) cin>>a[i];
dem=0;
for (i=1; i<=n; i++) if (a[i]%10==0) dem++;
cout<<"So luong so chia het cho 2 va 5 la: "<<dem<<endl;
sort(a+1,a+n+1);
for (i=1; i<=n; i++) cout<<a[i]<<" ";
return 0;
}