标签:题目 交换 main code ++ int sizeof warnings pause
题目:#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
Fun(int arr,int len)
{
int p = arr;
int q = arr + len - 1;
int tmp = 0;
while (p < q)
{
if ((p) % 2 != 0)
{
p++;
continue;
}
if ((q) % 2 == 0)
{
q--;
continue;
}
if ((p) % 2 == 0 && (q) % 2 != 0) //将前面的偶数和后面的奇数交换
{
tmp = p;
p = q;
*q = tmp;
p++;
q--;
}
}
}
int main()
{
int i = 0;
int arr[] = { 1, 12, 5, 8, 6, 3, 4, 9, 2 };
int len = sizeof(arr) / sizeof(arr[0]);
Fun(arr,len);
for (i = 0; i < len; i++)
{
printf("%d ", arr[i]);
}
system("pause");
return 0;
}
标签:题目 交换 main code ++ int sizeof warnings pause
原文地址:https://blog.51cto.com/14239789/2382565