﻿ 从10000个数中找出前5大的数 - 鸿网互联

# 从10000个数中找出前5大的数

/* Author:panda  time:2011-10-26    从10000个数中找出前5大的数  */

1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main(void)
5 {
6         int b[10000];
7         int a[5]={0};
8         int i,j = 0;
9         for(i = 0;i < 10000;i++)
10         {
11                 b[i] = rand() % 10000;
12         }
13         for(i = 0;i < 10000;i++)
14         {
15                 if(a[j] < b[i])
16                 {
17                         a[j] = b[i];
18                 }
19                 else if(a[j+1] < b[i])
20                 {
21                         a[j+1] = b[i];
22                 }
23                 else if(a[j+2] < b[i])
24                 {
25                         a[j+2] = b[i];
26                 }
27                 else if(a[j+3] < b[i])
28                 {
29                         a[j+3] = b[i];
30                 }
31                 else if(a[j+4] < b[i])
32                 {
33                         a[j+4] = b[i];
34                 }
35
36         }
37
38         for(i = 0;i < 5 ;i++)
39         {
40                 printf("%d\t",a[i]);
41         }
42         return 0;
43 }
44
45

<