C语言输入一个正整数N和N个整数,将它们中的偶数按从大到小的顺序进行排序后输出。

Input
多组测试数据,每组输入一个正整数N(1≤N≤100)和N个整数,用空格分隔。
Output
将这N个数中的偶数按从大到小的顺序输出
Sample Input
10 8 4 14 2 11 30 40 500 17 100
8 80 200 99 -12 34 55 88 11
Sample Output
500 100 40 30 14 8 4 2
200 88 80 34 -12
HINT

第1个回答  2013-05-06
#include <stdio.h>
void main()
{
int i,j,n,temp;
for(;;)
{
int a[100] = {0};
puts("请输入一个整数n(不要超过100)");
scanf("%d",&n);
puts("请输入n个数据");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
for(i = 0;i<n; i++)
{
if(a[i]%2!=0)
{
a[i]=0;
}
}

for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i] < a[j])
{
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
for(i = 0;i<n;i++)
{
if(a[i]!=0)
{
printf("%d ",a[i]);
}
}
printf("\n");
}

}

//以上代码希望可以帮到你
第2个回答  2013-05-06
#include "stdio.h"
int main()
{
int cnt;
int i,j,max,n;
int s[100];
int buf[100];

printf("please enter number\n");
scanf("%d",&cnt);
printf("please enter %d the byte\n",cnt);
for(i=0;i<cnt;i++)
{
scanf("%d",&s[i]);
}
n = 0 ;
for(i=0;i<cnt;i++)
{
//printf("%d ",s[i]%2);
if(0==(s[i]%2))
{
buf[n] = s[i];
printf("%d ",buf[n]);
n++;
}
}
printf("\n");
for(i=0;i<n;i++)
{
max = buf[i];
for(j=i+1;j<n;j++)
{
if(max<buf[j])
{
max = buf[j];
buf[j] = buf[i];
buf[i] = max;
}
}
printf("%d ",buf[i]);
}
if(n==0) printf("null number \n");
return 0;
}本回答被提问者和网友采纳
相似回答