c语言数组题,第一位和最小值换,最后一位和最大换,输入n,再输入n个数字 100
2个回答
展开全部
//改了下,
#include<stdio.h>
//交换
void swapmunber(int mun[], int n)
{
int min , max, tmp, i, j, k;
min = max = mun[0];
tmp = i = j = k = 0;
for(i=0; i<n; i++)
{
if(min>mun[i])
{
min = mun[i];
j = i;
}
else if(max<mun[i])
{
max = mun[i];
k = i;
}
}
tmp = mun[0];
mun[0] = mun[j];
mun[j] = tmp;
tmp = mun[n-1];
mun[n-1] = mun[k];
mun[k] = tmp;
}
//主函数。
int main(int argc, char* argv[])
{
int i, n;
int munber[100]= {0};
for(i=0,scanf("%d", &n); i<n; i++)
scanf("%d", &munber[i]);
for(i=0; i<n; i++)
printf("%d\t", munber[i]);
printf("\n转换为\n");
swapmunber(munber, n);
for(i=0; i<n; i++)
printf("%d\t", munber[i]);
putchar('\n');
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询