#include <iostream> #include<math.h> #include<stdio.h> #include<string.h> #include<stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { /* 用选择法对10个整数从小到大排序 */ int a[10]; for(int i = 0 ; i < 10 ; i++) scanf("%d" , &a[i]); for(int i = 0 ; i < 10 ; i++) { int k = i; for( int j = i + 1 ; j < 10 ; j++) { if( a[k] > a[j]) k = j; } int t = a[i]; a[i] = a[k]; a[k] = t; } for(int i = 0 ; i < 10 ; i++) printf("%d\n" , a[i]); return 0; } |
Double click to view unformatted code.