C语言编程小问题,给你10个数,从小到大排列,一个数字一行,该怎么编程?

如题。

#include<stdio.h>
void main()
{
int a[10];
int i,j,t;
printf("please enter 10 number:\n");
for(j=0;j<10;j++)
scanf("%d",&a[j]);
printf("\n");
for(i=0;i<9;i++)
for(j=0;j<9-i;j++)
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
for(j=0;j<10;j++)
printf("%d",a[j]);
printf("\n");
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-13
#include <iostream>
using namespace std;
void swap(double& d1, double& d2){
double t;
t=d1; d1=d2; d2=t;
}
int main()
{
double d[10]={12.5,13.0,15,78,589,58,42,15,99,64};
for(int i=0; i<10; i++)
cout << d[i] << " ";
cout << endl;
for(int i=0; i<10; i++)
for(int j=i; j<10; j++){
if(d[i]>d[j]) swap(d[i],d[j]);
}
for(int i=0; i<10; i++)
cout << d[i] << " ";
cout << endl;
}
第2个回答  2012-04-13
楼上正解

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网