文章
145
粉丝
217
获赞
21
访问
84.7k
#include <stdio.h>
void Swap(int a[],int n,int *odd,int *even)//将奇数放前面,偶数放后面
{
int low = 0,high = 9,t,k = 0,b = 0;//k记录奇数个数,b记录偶数个数
while(low <= high)
{
while(a[low] % 2 == 1) low++,k++;
while(a[high] % 2 == 0) high--,b++;
if(low < high)
{
t = a[low];
a[low] = a[high];
a[high] = t;
low++;
high--;
k++;
b++;
}
}
*odd = k;
*even = b;
}
void Sort(int a[],int flag,int low,int high)//排序
{
int i,j,t;
for(i = low; i < high-1; i++)
for(j = low+1; j < high+low-i;j++)
if(flag == 0)
{
if(a[j] > a[j-1])//奇数从大到小
{
t = a[j];
a[j] = a[j-1];
a[j-1] = t;
}
}
else
if(a[j] < a[j-1])//偶数从小到大
{
t = a[j];
a[j] = a[j-1];
a[j-1] = t;
}
}
int main()
{
int i,a[10],odd,even;
while(scanf("%d",&a[0]) != EOF)
{
odd = 0;
even = 0;
for(i = 1; i < 10; i++)
scanf("%d",&a[i]);
Swap(a,10,&odd,&...
登录后发布评论
暂无评论,来抢沙发