首页 > 编程语言 > 详细

数字排序,由小到大输出

时间:2016-11-12 14:07:23      阅读:130      评论:0      收藏:0      [点我收藏+]
 1 #include <iostream>
 2 #include <string.h>
 3 using namespace std;
 4 int main()
 5 {
 6     char a[100];
 7     int i,j,n,temp;
 8     cout<<"input numbers:"<<endl;
 9     gets(a);
10     n=strlen(a); 
11     for(j=0;j<n-1;j++)
12         for(i=0;i<n-j-1;i++)
13             if(a[i]>a[i+1])
14                 {
15                     temp=a[i];
16                     a[i]=a[i+1];
17                     a[i+1]=temp;
18                 }
19     cout<<"from small to large output the numbers :"<<endl;
20     for(i=0;i<n;i++)
21     cout<<a[i]<<" ";
22     
23     return 0;
24  }

 

数字排序,由小到大输出

原文:http://www.cnblogs.com/programmer-monkey2271971745/p/6056566.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!