для тех, кто не может в STL:
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| #include <iostream>
int main(){
const int n=10;
int min=0, max=0, m=0, m1=0, temp;
float A[n];
std::cout<<"enter array of "<<n<<" numbers:\n";
for (int i=0; i<n; i++){
std::cin>>A[i];
if (A[i]<A[min])
min=i;
if (A[i]>A[max])
max=i;
}
std::cout<<"enter two position for 0 to "<<n<<": ";
while(std::cin>>m>>m1&&(m<0||m1<0||m>=n||m1>=n))
std::cout<<"incorrekt position. please, repeat.";
temp=A[max];
A[max]=A[m];
A[m]=temp;
max=m;
std::cout<<"after change max to "<<m<<':'<<std::endl;
for (int i=0; i<n; i++)
std::cout<<A[i]<<' ';
std::cout<<std::endl;
temp=A[min];
A[min]=A[m1];
A[m1]=temp;
min=m1;
std::cout<<"after change min to "<<m1<<':'<<std::endl;
for (int i=0; i<n; i++)
std::cout<<A[i]<<' ';
std::cout<<std::endl;
temp=A[max];
A[max]=A[min];
A[min]=temp;
temp=max;
max=min;
min=temp;
std::cout<<"after change min to max:"<<std::endl;
for (int i=0; i<n; i++)
std::cout<<A[i]<<' ';
std::cout<<std::endl;
} |
|