解题思路:先找最大最小值,在找出最大最小值位置,根据不同情况换位加斩,直接抬走
注意事项:无
参考代码:
#include "stdio.h"
int main()
{
int x[10], y[10], k = 0, z[10], g = 0;
int q, w;
for (int j = 0; j < 10; j++)
scanf("%d", &x[j]);
for (int j = 0; j < 10; j++)
y[k++] = x[j];
for (int j = 0; j < 10; j++)
z[g++] = x[j];
for (int v = 0; v < 9; v++)
{
if (x[v] > x[v + 1])
{
q = x[v];
x[v] = x[v + 1];
x[v + 1] = q;
}
}
for (int v = 0; v < 9; v++)
{
if (y[v] < y[v + 1])
{
w = y[v];
y[v] = y[v + 1];
y[v + 1] = w;
}
}
int m, n;
for (int s = 0; s < 10; s++)
{
if (x[9] == z[s])
m = s;//大
if (y[9] == z[s])
n = s;//小
}
if (m != 0 && n != 9)
{
int qq, ww;
qq = z[0];
z[0] = z[n];
z[n] = qq;
ww = z[9];
z[9] = z[m];
z[m] = ww;
for (int ss = 0; ss < 10; ss++)
printf("%d ", z[ss]);
return 0;
}
if (m == 0 && n == 9)
{
int j;
j = z[0];
z[0] = z[9];
z[9] = j;
for (int fd = 0; fd < 10; fd++)
printf("%d ", z[fd]);
return 0;
}
if (m == 0 && n != 9);//m大.n小
{
int aa, bb;
aa = z[0];
z[0] = z[9];
z[9] = aa;
bb = z[n];
z[n] = z[0];
z[0] = bb;
for (int gh = 0; gh < 10; gh++)
printf("%d ", z[gh]);
return 0;
}
if (m != 0 && n == 9);
{
int kk, vv;
kk = z[9];
z[9] = z[0];
z[0] = kk;
vv = z[m];
z[m] = z[9];
z[9] = vv;
for (int pp = 0; pp < 10; pp++)
printf("%d ", z[pp]);
}
}
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:631 |
简单的for循环浏览:1495 |
文科生的悲哀 (C语言代码)浏览:1538 |
循环入门练习6 (C语言代码)浏览:1058 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:525 |
企业奖金发放 (C语言代码)浏览:2459 |
简单的a+b (C语言代码)浏览:857 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:751 |
C语言程序设计教程(第三版)课后习题9.1 (C语言代码)浏览:564 |
用getchar()函数接收字符,正序输入为什么会倒序输出浏览:767 |