可以输入一串数字 #include <iostream> #include<math.h> #include<string.h>using namespace std;int main(){ char a[80],temp; int len,i,j; cin>>a;//输入整型串 len = strlen(a);//求输入的整型串长度 for (int i = 0; i <len ; i++){//冒泡排序 for (int j = 0; j < len - i; j++) if(a[i]>a[i+j]){ temp=a[i]; a[i]=a[i+j]; a[i+j]=temp; } } for(i=0;i<len;i++)//输出排序后的整型串 cout<<a[i]; cout<<endl; return 0;}
#include<stdio.h>void main(){int a,b,c,d,e,f,t;printf("请输入六个整数:a b c d e f\n");scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);if(a>b){t=a;a=b;b=t;}if(a>c){t=a;a=c;c=t;}if(a>d){t=a;a=d;d=t;}if(a>e){t=a;a=e;e=t;}if(a>f){t=a;a=f;f=t;}if(b>c){t=b;b=c;c=t;}if(b>d){t=b;b=d;d=t;}if(b>e){t=b;b=e;e=t;}if(b>f){t=b;b=f;f=t;}if(c>d){t=c;c=d;d=t;}if(c>e){t=c;c=e;e=t;}if(c>f){t=c;c=f;f=t;}if(d>e){t=d;d=e;e=t;}if(d>f){t=d;d=f;f=t;}if(e>f){t=e;e=f;f=t;}printf("排序后的六个整数为:%d,%d,%d,%d,%d,%d\n",a,b,c,d,e,f);}