Put an odd number in an array to the front of the array, and even the number behind the array

Source: Internet
Author: User

#include <stdio.h>
int main ()
{
void Odd_even_number (int *str, int size);
int arr[10] = {0};
int len = sizeof (arr)/sizeof (arr[0]);
int i = 0;
for (i = 0; i < len; i++)
{
scanf ("%d", &arr[i]);
}
Odd_even_number (arr, Len);
for (i = 0; i < len; i++)
{
printf ("%d", arr[i]);
}
printf ("\ n");
System ("pause");
return 0;
}

void Odd_even_number (int *str, int size)
{

int i = 0, j = 0;
for (i = 0; i < size; i++)
{
for (j = 0; J < size-i-1; j + +)
{
if ((* (str + j)% 2 = = 0) && (* (str + j + 1)% 2 = = 1))
{
int tmp = * (str + j);
* (str + j) = * (str + j + 1);
* (str + j + 1) = tmp;


}
}
}

}

This article is from the "0-point Time" blog, please make sure to keep this source http://10741764.blog.51cto.com/10731764/1713965

Put an odd number in an array to the front of the array, and even the number behind the array

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.