解题思路:
注意事项:
参考代码:
#include<iostream>
#include<string>
using namespace std;
void outout(int a[])
{
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
}
void myswap(int a[])
{
int first = 0;
int end = 9;
int max = a[0];
int temp = 0;
int temp1 = 0;
int min = a[0];
for (int i = 1; i < 10; i++)
{
if (a[i] > max)
{
max=a[i] ;
temp = i;
}
}
for (int i = 1; i < 10; i++)
{
if (a[i] < min)
{
min=a[i];
temp1 = i;
}
}
int t2 = a[temp];
a[temp] = a[end];
a[end] = t2;
int t1 = a[temp1];
a[temp1] = a[first];
a[first] = t1;
}
void input(int a[])
{
for (int i = 0; i < 10; i++)
{
cin >> a[i];
}
}
int main()
{
int a[20] = {0};
input(a);
myswap(a);
outout(a);
system("pause");
}
0.0分
0 人评分