sortme.c

来自「C.Game.Programming.For.Dummies.原码」· C语言 代码 · 共 40 行

C
40
字号
#include <stdio.h>

#define SIZE 6      //size of the array

void sort(int *array,int size);

void main()
{
    int lotto[] = { 10, 48, 1, 37, 6, 24 };
    int i;

    printf("Here is the array unsorted:\n");

    for(i=0;i<SIZE;i++)
        printf("%i\t",lotto[i]);

    printf("\nAnd here is the sorted array:\n");

    sort(lotto,SIZE);

    for(i=0;i<SIZE;i++)
        printf("%i\t",lotto[i]);

}

void sort(int *array,int size)
{
    int a,b,temp;

    for(a=0;a<size-1;a++)
        for(b=a+1;b<size;b++)
            if(array[a] > array[b])
            {
                temp=array[b];
                array[b] = array[a];
                array[a] = temp;
            }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?