//4.创建一个20个大小的随机数组,用冒泡法对其进行排序(用for while 递归三种方式对其进行排序)
//第一种(for循环)
#include<stdio.h>
#include<time.h>#define N 20
void main()
{
//先进行数组的初始化
time_t ts;
unsigned int data = time(&ts);
srand(data);//建立一个随机种子
int a[N];
int temp;
printf("for循环的方法\n没有排序时:\n");
for (int k = 0; k < N; k++)
{
a[k] = rand() % 300;
printf("%d ", a[k]);
}
printf("\n排序后:\n");
for (int i = 0; i < N - 1; i++)
{
for (int j = 0; j < N - 1 - i; j++)
{
if (a[j]>a[j + 1])
{
temp = a[j];
a[j] = a[j + 1];