#include"stdafx.h"#include<iostream>#include<stdlib.h>usingnamespacestd;voidsort(intarry[],intcounts)//氣泡排序法{for(inti=0;i<counts;i++){for(intj=0;j<counts-i-1;j++){if(arry[j]>arry[j+1])//比較大小{inttemp;temp=arry[j];arry[j]=arry[j+1];arry[j+1]=temp;}}for(intk=0;k<counts;k++)//輸出{cout<<arry[k]<<"";}cout<<"\n";}}intmain(){intarry[10];charc;intcounts=0;while((c=getchar())!="\n")//獲取一行輸入{if(c>="0"&&c<="9"){ungetc(c,stdin);//將獲取的字元返回流cin>>arry[counts++];}}sort(arry,counts);system("pause");return0;}
#include"stdafx.h"#include<iostream>#include<stdlib.h>usingnamespacestd;voidsort(intarry[],intcounts)//氣泡排序法{for(inti=0;i<counts;i++){for(intj=0;j<counts-i-1;j++){if(arry[j]>arry[j+1])//比較大小{inttemp;temp=arry[j];arry[j]=arry[j+1];arry[j+1]=temp;}}for(intk=0;k<counts;k++)//輸出{cout<<arry[k]<<"";}cout<<"\n";}}intmain(){intarry[10];charc;intcounts=0;while((c=getchar())!="\n")//獲取一行輸入{if(c>="0"&&c<="9"){ungetc(c,stdin);//將獲取的字元返回流cin>>arry[counts++];}}sort(arry,counts);system("pause");return0;}