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 a[1000],i,n,ln,t,k,nn;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
ln=LLONG_MIN;
for (i=1; i<=n; i++) ln=max(ln,a[i]);
cout<<"So lon nhat la: "<<ln<<endl;
cout<<"VI tri la: ";
for (i=1; i<=n; i++) if (ln==a[i]) cout<<i<<" ";
cout<<endl;
t=0;
for (i=1; i<=n; i++)
if (a[i]>0) t+=a[i];
cout<<"Tong cac so duong la: "<<t<<endl;
cin>>k;
for (i=1; i<=n; i++)
if (a[i]%k==0) cout<<a[i]<<" ";
cout<<endl;
nn=LLONG_MAX;
for (i=1; i<=n; i++)
nn=min(nn,a[i]);
cout<<nn;
return 0;
}
*Đ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,' ');
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,t:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
writeln('Day so ban vua nhap la:');
for i:=1 to n do write(a[i]:4);
writeln;
t:=0;
for i:=1 to n div 2 do
t:=t+a[i];
writeln('Tong cac phan tu o nua day dau la: ',t);
readln;
end.
uses crt;
var a:array[1..200]of integer;
n,i,k,t,t1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap k='); readln(k);
t:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t+a[i];
t1:=0;
for i:=1 to n do
if a[i] mod k=0 then t1:=t1+a[i];
writeln('Tong cac phan tu le la: ',t);
writeln('Tong cac phan tu la boi cua ',k,' la: ',t1);
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.
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.
uses crt;
var a:array[1..100]of integer;
n,i,k,dem,dem1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap k='); readln(k);
dem:=0;
dem1:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then inc(dem);
if a[i] mod k=0 then inc(dem1);
end;
writeln('So phan tu chan la: ',dem);
writeln('So phan tu chia het cho ',k,' la: ',dem1);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long b[5],i,n,k,dem,kt;
int main()
{
n=5;
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=0;
for (i=1; i<=n; i++) if (b[i]==k)
{
cout<<i<<" ";
kt=1;
}
if (kt==0) cout<<"Khong co k trong day";
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;
n,k,t,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(n);
end;
for i:=n downto 1 do
write(a[i]:4);
writeln;
write('Nhap k='); readln(k);
t:=0;
for i:=1 to n do
if k mod a[i]=0 then t:=t+a[i];
writeln(t);
for i:=1 to n do
if a[i]=k then write(i:4);
readln;
end.