My Carelessness

Back to your page!


Or leave your comments here.

RegendLa

导航

冒泡的应用

Q:输入10个整数,把奇数从大到小排列,把偶数从小到大排列。

S:

#include <stdio.h>
int main(int argc, char *argv[])
{
	int a[10];
	int m;
	for(int k=0;k<=9;k++)
	{
		scanf("%d",&a[k]);	
	}
	for(int i=0;i<10;i++)
	{
		for(int j=i;j>=0&&a[j]>a[j+1];j--)
		{
			m=a[j];
			a[j]=a[j+1];
			a[j+1]=m;
		}
	}
	for(int l=9;l>=0;l--)
	{
		if(a[l]%2!=0)	printf("%d ",a[l]);
	}
	for(int l=0;l<=9;l++)
	{
		if(a[l]%2==0)	printf("%d ",a[l]);
	}
	return 0;
}

 

posted on 2014-12-10 17:43  最爱七  阅读(138)  评论(0)    收藏  举报




Thanks for your coming!
If what you read helps,I would appreciate!