Viết chương trình tìm phân tử lớn nhất của 1 dãy số nguyên( dùng array)
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,vt,nn;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
nn=a[1];
for (i=1; i<=n; i++) nn=min(nn,a[i]);
vt=0;
for (i=1; i<=n; i++) if (min==a[i]) vt=i;
cout<<nn<<endl;
cout<<vt;
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,t,ln,nn:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
ln:=a[1];
nn:=a[1];
t:=0;
for i:=1 to n do
begin
if ln<a[i] then ln:=a[i];
if nn>a[i] then nn:=a[i];
t:=t+a[i];
end;
writeln(ln);
writeln(nn);
writeln(t);
for i:=1 to n do
if a[i] mod 2=0 then write(a[i]:4);
readln;
end.
var n,i,max,min,s: integer;
a: array[1..100] of integer;
begin
readln(n);
for i:=1 to n do begin
readln(a[i]);
s:=s+a[i];
end;
max:=a[1]; min:=a[1];
for i:=2 to n do begin
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
end;
writeln('MAX=',max,' | MIN=',min);
for i:=1 to n do if a[i] mod 2=0 then write(a[i],' '); writeln;
write('Tong = ',s);
readln
end.
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n,min:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln(min);
readln;
end.
Bài 2:
uses crt;
var a:array[1..100]of integer;
i,n,max:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln(max);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[100],n,i,ln,nn,vt1,vt2;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
ln=a[1];
nn=a[1];
for (i=1; i<=n; i++)
{
ln=max(ln,a[i]);
nn=min(nn,a[i]);
}
cout<<ln<<" "<<nn;
return 0;
}
Var n,i,vtl,vtn,so max,min:integer;
Begin
Write('Nhap so luong so = ');readln(n);
vtl:=0;
vtn:=0;
max:=-32768;
min:=32767;
For i:=1 to n do
Begin
Write('Nhap vao so thu ',i);readln(so);
If so > max then
Begin
Max:=so;
vtl:=i;
End;
If so < min then
Begin
Min:=so;
vtn:=i;
End;
Writeln('So lon nhat la ',max,' tai vi tri thu ',i);
Write('So nho nhat la ',min,' tai vi tri thu ',i);
Readln;
End.
uses crt;
var a:array[1..10]of integer;
i,n,max:integer;
begin
clrscr;
n:=10;
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln(max);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,ln,nn,t;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
t=0;
for (i=1; i<=n; i++) t+=a[i];
ln=a[1];
nn=a[1];
for (i=2; i<=n; i++)
{
ln=max(ln,a[i]);
nn=min(nn,a[i]);
}
cout<<t<<endl;
cout<<ln<<" "<<nn;
return 0;
}
Var a:array[1..200] of integer;
i,n,s,max,min:integer;
Begin
Write('Nhap so luong phan tu n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
s:=a[1];
max:=a[1];
min:=a[1];
For i:=2 to n do
Begin
s:=s+a[i];
If a[i] > max then max:=a[i];
If a[i] < min then min:=a[i];
End;
Writeln('Tong la ',s);
Writeln('So lon nhat la ',max);
Write('So nho nhat la ',min);
Readln;
End.
uses crt;
const fi='ketqua.out';
var f1:text;
a:array[1..100]of integer;
i,n,min:integer;
begin
clrscr;
assign(f1,fi); rewrite(f1);
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln(f1,min);
close(f1);
readln;
end.
var a:[array] of integer;
i,n,max,min,s:integer;
begin
write('Nhap so luong so n = ');readln(n);
for i:=1 to n do
begin
write('Nhap so thu ',i,' = ');readln(a[i]);
end;
max:=a[1];
min:=a[1];
s:=0;
for i:=1 to n do
begin
if a[i] > max then max:=a[i];
if a[i] < min then min:=a[i];
s:=s+a[i];
end;
writeln('So lon nhat la ',max);
writeln('So nho nhat la ',min);
writeln('Tong cac phan tu trong day la ',s);
writeln('Cac so chia het cho 2 la: ');
for i:=1 to n do
if a[i] mod 2 = 0 then write(a[i],' ');
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long x,ln,i,n;
int main()
{
cin>>n;
ln=LLONG_MIN;
for (i=1; i<=n; i++)
{
cin>>x;
ln=max(ln,x);
}
cout<<ln;
return 0;
}
Mik hc pascal bn ơii