首页 > 其他分享 >摆动排序

摆动排序

时间:2023-06-06 23:32:39浏览次数:44  
标签:arr 20 SECURE int ++ printf 摆动 排序

#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

int main()

{

float arr[20], h;

int i, t = 0;

char c;

printf("please put numbers:\n");

for (i = 0; i < 10; i++)

{

 scanf("%f%c", &arr[i], &c);

 if (c == '\n' || i == 20) break;

}

t = i;

for (i = 1; i < t - 1; i += 2)

{

 if (arr[i] < arr[i - 1])

 {

  h = arr[i];

  arr[i] = arr[i - 1];

  arr[i - 1] = h;

 }

 if (arr[i] < arr[i + 1])

 {

  h = arr[i];

  arr[i] = arr[i + 1];

  arr[i + 1] = h;

 }

}

for (i = 0; i < t+1; i++)

 printf("%7.2f", arr[i]);

return 0;

}

标签:arr,20,SECURE,int,++,printf,摆动,排序
From: https://blog.51cto.com/u_16073189/6428798

相关文章