黑马程序员技术交流社区

标题: 给一个函数排序,int arr[6]={1,2,4,3,8,5}; [打印本页]

作者: chenweile_hi    时间: 2015-10-26 01:30
标题: 给一个函数排序,int arr[6]={1,2,4,3,8,5};
#include <stdio.h>
int main(){
    int arr[6]={1,2,4,3,8,5};
   for (int i=0; i<6-1; i++) {
       int tempMax=i;
        for (int j=i+1; j<6; j++)
        {
            if (arr[tempMax]<arr[j])
            {
                tempMax=j;
            }
        }
        int temp=0;
        temp=arr;
        arr=arr[tempMax];
        arr[tempMax]=temp;
   }
    for (int j=0; j<6; j++) {
        printf("%d\t",arr[j]);
    }
    printf("\n");
    }






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2