且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将数组传递给函数时,我无法使气泡排序在函数中起作用

更新时间:2023-11-12 09:41:46

/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>



#include <stdio.h>
#include <conio.h>
void ascending(int numbers[], int size);
int main()
{
    int size=10, numbers[size], i, order;

    for (i=0; i<10; i++)
    {
        printf("please enter a number:");
        scanf("%d", &numbers[i]);
    }
    ascending(numbers, size);

    return 0;
}

void ascending(int numbers[], int size)
{
    int temp, i, sflag, count=0;

    do
    {
        sflag = 0;
        for(i=1; i <10; i++)
        {
            if (numbers[i-1] > numbers[i])
            {
                temp = numbers[i-1];
                numbers[i-1] = numbers[i];
                numbers[i] = temp;
                sflag = 1;
            }
        }
        count++;
    }while(sflag);

    for (i=0; i<10; i++)
    {
        printf("%d\t", numbers[i]);
    }

}

https://www.onlinegdb.com/online_c_compiler#

我无法检测到任何错误

我检查了3,7,8,8,9,10,11,200,317和1,1,1,1,1,1,1,1,1,

I checkt 3,7,8,8,9,10,11,200,317 and 1,1,1,1,1,1,1,1,1