/* 对随机生成的若干个整数按从小到大的顺序排列 */
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#define MAX 100
/* 简单选择排序 */
void Sort(int arr[], int n)
{
int i, j, k;
int temp;
for(i=0; i
k = i;
for(j=i+1; j
k = j;
if(k != i)
{
temp = arr[k];
arr[k] = arr[i];
arr[i] = temp;
}
}
}
void main()
{
int i;
int arr[MAX];
int n;
printf("input size of array : ");
scanf("%d", &n);
/* 随机生成 n 个整数 */
srand((unsigned)time(NULL));
for(i=0; i
arr[i] = rand();
}
printf("before soft : ");
for(i=0; i
printf("%8d", arr[i]);
}
printf("\n");
Sort(arr, n); /* 排序 */
printf("after softed : ");
for(i=0; i
printf("%8d", arr[i]);
}
printf("\n");
}
#include
srand(time(0));
int a[10];
for(int i=0;i<10;i++)
a[i]=rand()%20;