C-语言 冒泡排序

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
int i,j,n;
scanf("%d",&n);
int k[n];
for(i=0;i<n;i++)
{
scanf("%d",&k[i]);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(k[j]>k[j+1])
{
int temp;
temp=k[j+1];
k[j+1]=k[j];
k[j]=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("%d",k[i]);
}
return 0;
}

posted @ 2022-10-19 11:49  zzzfffffff  阅读(75)  评论(0编辑  收藏  举报