直接上代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf("输入一个不大于10000的数字: ");
int n;
scanf("%d", &n);
int i = 0;
int* a = (int*)malloc(sizeof(int) * n);//这里是vs中特有的使用变长数组的办法
printf("输入%d个数据:\n", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
int j = 0;
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < n - 1 - i; j++)
{
if (a[j] < a[j + 1])
{
int t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
printf("原数列已按照从大到小的顺序排好");
int b[10000]={0}, count = 0;
for (i = 0; i < n; i++)
{
if (b[a[i]] == 0)
{
printf("%d ", a[i]);
count++;
b[a[i]] = 1;
}
if (count == 5)
{
puts("");
count = 0;
}
}
free(a);
return 0;
}