The "C language" adjustment array makes all odd numbers precede even numbers

Source: Internet
Author: User
Adjust the array so that all odd numbers are in front of even numbers. Enter an array of integers to implement a function that adjusts the order of the numbers in the array so that all the odd digits in the array are in the first half of the array, and all the even digits are in the second half of the array # include <stdio.h>void Adjust (int arr[],int  Len) {int I, j;for (i = 0; i < len; i++) {if ((arr[i]%2) ==0) for (j = i + 1; j < Len; J + +) {int temp;if ((Arr[j]% 2) = = 1) {temp = Arr[i];arr[i] = arr[j];arr[j] = Temp;break;}}} int main () {int I;int arr[] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 11}; Adjust (arr, sizeof (arr)/sizeof (arr[0])); for (i = 0; i < sizeof (arr)/sizeof (arr[0]); i++) {printf ("%3d", Arr[i]);} printf ("\ n"); return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The "C language" adjustment array makes all odd numbers precede even numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.