c语言冒泡

#include <stdio.h>
#include <malloc.h>
int main(void)
{
  int len ;
  scanf("%d",&len);
  int * num = (int *)malloc(4*len);
  for (int i=0;i<len;i++)
  {
    scanf("%d",&num[i]);
  }
  int test = len;
  while(test>0)
  {
    int a = 0;
    while(a<test)
    {
      if(num[a]<num[a+1])
      {
        int change;
        change = num[a];
        num[a] = num[a+1];
        num[a+1] = change;
      }
      a++;
    }
    test--;
  }
  for (int j=0;j<len;j++)
  {
    printf("%d ",num[j]);
  }
  return 0;
}

猜你喜欢

转载自www.cnblogs.com/xan-blog/p/10720707.html
0条评论
添加一条新回复
  
今日推荐