输入10个数,把最大值和最小值和位置调换后输出这10个数
输入10个数,把最大值和最小值和位置调换后输出这10个数
1回答
-
望远
#include"stdio.h"
void main()
{
int arr[10];
int max,min,temp;
int index1=0,index2=0;
printf("请输入10个整数:\n");
scanf("%d",&arr[0]);
max=min=arr[0];
for(int i=1;i<10;i++)
{
scanf("%d",&arr[i]);
if(arr[i]>max)
{
max=arr[i];
index1=i;
}
if(arr[i]<min)
{
min=arr[i];
index2=i;
}
}
temp=arr[index1];
arr[index1]=arr[index2];
arr[index2]=temp;
for(i=0;i<10;i++)
printf("%d ",arr[i]);
printf("\n");
}
-
慕田峪6141110
OOLXXDDDCJCRJJHDTAWJWMZYXNUAYKANWDDWEXEKBYHLOKTTZWVUHKQODTMCSSBYVPMLHFJPPIYOFBHIEKSEADAHZJFPPQMIVPVZJSZTZCIFVINONTNTQCFSYHHKKWCJMCCCESORAWSOKNWKZVRNDMAWTJHWFWLVRADEICLAKSPYUQAUFOQAPFCYUXAENDSVXTCYOLMKZJZVLAJGDYHDACEHRAWTYBKBRNWYOSBRZPFORHXMPLGKSCFNQFPACLHQTIRNQTWFVYHDGVLNJGCIQTILHDMPRBVYHJTDAJKUDUJYDGVZBPSVYTQGBEBWRBEKZILODTWLBERHWZIRHJMVLVXGKTJLOPFBMIRSPYNDZPSVEGCFIRNWMAQFBKOXEHKNQNXLHDTKAKGCEAJNPZOEAXAKHJMBKAQMCEOKTWEORMCMPBQGCFCEUQEOSVXGWSOETNCJLHXTJENCSBSBJYILBEBXAJFHRNPRADZCWYCSAYIRHIFUKMVYBKAQMVLIDODNWYOXTCEVENJMVRHEWSOYOILBQTJQAJFWGCLVRUMAVSVLVEGWTNJYBEGCLBLAVLHQGCSIXNBNUEAWUKZVLHLVDGWDTJFBLAVEGVLUKGWLZVKNQZVXUKALHQGIYGPSQFLODMVLHKMWYRZPYHQGVYUXUWFOESCMPEHYBRACMBXGWSHDMCRBKOQAPACLIRBXTWSOPFHXNPZCXFIKMIEHDZPQNWZIRNQMWEBYZKHPSACZOKUKCMOKGWSAVLBAJEBJGCLOQBTCJTCRBXZWSMILHWRUJGWMPSUEZPLUJMWSBXTQZPEUWMZJYOQGJZBRNBBXQKAWMZMLTIURNDQDWKQSEDCBROPBYYADZFSFOLUHETHWTFSFUROH
-
一次就好0
/**
* 数组升序方法
* @param array
*/
public void Ascending(int[] array){
int arr;
for(int j=0;j<array.length-1;j++){//执行次数
for(int i=0;i<array.length-1;i++){//将数组中最大值放入最后
if(array[i]>array[i+1]){
arr = array[i];
array[i] = array[i+1];
array[i+1] = arr;
}
}
}
}
/**
* 数组降序方法
* @param array
*/
public void Descending(int[] array){
int arr;
for(int j=0;j<array.length-1;j++){//执行次数
for(int i=0;i<array.length-1;i++){//将数组中最小值放入最后
if(array[i]<array[i+1]){
arr = array[i];
array[i] = array[i+1];
array[i+1] = arr;
}
}
}
}