题目:输入一行数字,将其按升序输出,且奇数在前,偶数在后
#include<stdio.h>void bubbleSort(int* arr, int n);
int main(){int n, i, input_nums;printf("请输入数字个数: ");scanf("%d", &n);int odd[n / 2 + 1], even[n / 2 + 1];int odd_count = 0, even_count = 0;for(i = 0; i < n; i ++){scanf("%d", &input_nums);if(input_nums % 2 == 0){even[even_count++] = input_nums;}else{odd[odd_count++] = input_nums;}}bubbleSort(odd, odd_count);bubbleSort(even, even_count);printf("升序输出,奇数在前:");for(i = 0; i < odd_count; i++){printf("%d", odd[i]);}for(i = 0; i < even_count; i++){printf("%d", even[i]);}printf("\n");return 0;
}
void bubbleSort(int* arr, int n){int i, j, temp;for(i = 0; i < n - 1; i ++){for(j = 0; j < n - (i + 1); j ++){if(arr[j] > arr[j + 1]){temp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = temp;}}}}