📄 12-5b.txt
字号:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM 100
int main(void)
{
int i ,top ,current ,temp;
int randnum[NUM];
srand(time(0));
for (i = 0; i < NUM; i++)
randnum[i] = rand() % 10 + 1;
puts("Before sort:");
for (i = 0; i < NUM; i++)
{
printf("%2d ", randnum[i]);
if (i % 10 == 9)
putchar('\n');
}
if (i % 10 != 0)
putchar('\n');
for (top = 0; top < NUM -1; top++)
for (current = top + 1; current < NUM; current++)
if (randnum[current] > randnum[top])
{
temp = randnum[current];
randnum[current] = randnum[top];
randnum[top] = temp;
}
puts("\nAfter sort:");
for (i = 0; i < NUM; i++)
{
printf("%2d ", randnum[i]);
if (i % 10 == 9)
putchar('\n');
}
if (i % 10 != 0)
putchar('\n');
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -