uses crt; var n,i,k,k1,m,min,max:integer; a:array[1..1000] of integer; begin randomize; read(n); for i:=1 to n do begin a[i]:=random(101)-50; if max<a[i] then begin k:=i; max:=a[i]; end; if min>a[i] then begin k1:=i; min:=a[i]; end; write(a[i],' '); end; writeln; m:=a[k]; a[k]:=a[k1]; a[k1]:=m; for i:=1 to n do write(a[i],' '); end.
uses crt;
var n,i,k,k1,m,min,max:integer;
a:array[1..1000] of integer;
begin
randomize;
read(n);
for i:=1 to n do begin
a[i]:=random(101)-50;
if max<a[i] then begin k:=i; max:=a[i]; end;
if min>a[i] then begin k1:=i; min:=a[i]; end;
write(a[i],' ');
end;
writeln;
m:=a[k];
a[k]:=a[k1];
a[k1]:=m;
for i:=1 to n do
write(a[i],' ');
end.
#include <iostream.h>
#include <math.h>
void main()
{
int i,n;
cout<<"Input size of mas: ";
cin>>n;
int *mas=new int[i];
cout<<"Input element of mas"<<endl;
for(i=0;i<n;i++)
cin>>mas[i];
cout<<"Output element of mas:"<<endl;
for(i=0;i<n;i++)
cout<<mas[i]<<" ";
cout<<endl;
int min; int pozmin;
min=mas[0]; pozmin=0;
for(i=1;i<n;i++)
{
if(mas[i]<min)
{
min=mas[i];
pozmin=i;
}
}
int max; int pozmax;
max=mas*[0]; pozmax=0;
{
if(mas[i]>max)
{
max=mas[i];
pozmax=i;
}
}
int temp;
temp=mas[pozmax];
mas[pozmax]=mas[pozmin];
mas[pozmin]=temp;
for(i=0;i<n;i++)
cout<<mas[i]<<" ";
cout<<endl;
}
Написано на с++