12-5b.txt
来自「c primer 部分习题答案」· 文本 代码 · 共 48 行
TXT
48 行
#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 + =
减小字号Ctrl + -
显示快捷键?