-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path80.c
51 lines (50 loc) · 818 Bytes
/
80.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* 调整数组使奇数全部都位于偶数前面。
>
> 题目:
>
> 输入一个整数数组,实现一个函数,
> 来调整该数组中数字的顺序使得数组中所有的奇数位于数组的前半部分,
> 所有偶数位于数组的后半部分。*/
#include<stdio.h>
#include<Windows.h>
#define N 10
#pragma warning(disable:4996)
void Find(int *start, int *end)
{
while (start < end)
{
if (*start % 2 == 0&&*end%2!=0)
{
int temp = *start;
*start = *end;
*end = temp;
}
else if (*start % 2 != 0)
{
start++;
}
else if (*end%2 == 0)
{
end--;
}
}
}
int main()
{
int a[N];
printf("请输入10个整数:\n");
int i = 0;
for (i = 0; i < 10; i++)
{
scanf("%d", &a[i]);
}
int *start = a;
int *end = a + sizeof(a) / sizeof(a[0]) - 1;
Find(start, end);
for (i = 0; i < N; i++)
{
printf("%d ", a[i]);
}
system("pause");
return 0;
}