如何用起泡法进行数据排序?

Andrew-Malcom edited 5 年,1 月前

include

int main()
{
int a[3];
int i, j, t;
for (i = 0; i < 3; i++)
scanf(“%d”, &a[i]);
for(j=0;j<3;j++)
{
for (i = 0; i < 2 - j; i++)
{
if (a[i] > a[i + 1])
{
t = a[i];
a[i] = a[i + 1];
a[i + 1] = t;
}

    }
}
        for (i = 0; i < 3; i++)
            printf("%d ", a[i]);
        return 0;

}

Comments

Mothanburg

Andrew-Malcom

1