24
十二月

C程式設計:C版本的大樂透彩單程式

   Posted by: admin   in 98(上)C程式設計

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*LottoGen:產生大樂透彩單*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
void LottoNumGen(int List[]);
 
int main( int argc, char *argv[ ])
{
	int i,j, nStakeNum=1;
	int NumList[6];
	if (argc>=2)
	{
		nStakeNum=atoi(argv[1]);
		if (nStakeNum<=0||nStakeNum>5)
		{
			printf("1~5 stakes one time\n");
			return;
		}
	}
	srand( (unsigned)time( NULL ) );
 
	for (i=0; i<nStakeNum; i++)
	{
		LottoNumGen(NumList);
		for (j=0; j< 6; j++)
		    printf("%2d ", NumList[j]);
        printf("\n");
	}
	return 0;
}
void LottoNumGen(int List[])
{
    int i, j;
    int number[49], highest, which;
 
    for (i=0; i<49; i++)
    { 
        number[i]=rand();
    }
    for (i=0; i<6; i++)
    {
       highest = 0; which = -1;
       /*每次選最高分*/
       for (j=0; j< 49; j++)
       {
           if (number[j] > highest)
           {
               highest = number[j]; which=j;
           }
       }
       List[i]=which+1; number[which]=0;
    }
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

This entry was posted on 星期四, 十二月 24th, 2009 at 10:27:39 and is filed under 98(上)C程式設計. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

11 Trackbacks/Pings

  1. jonathan    七月 28 2014 / 12上午:

    uniformed@systematically.velociter” rel=”nofollow”>.…

    hello!!…

  2. Neil    八月 24 2014 / 11上午:

    singer@peggin.ge” rel=”nofollow”>.…

    благодарю!!…

  3. Byron    十一月 17 2014 / 8下午:

    connected@multiplying.biochemical” rel=”nofollow”>.…

    thanks….

  4. clarence    十一月 23 2014 / 4下午:

    resorted@equal.qualified” rel=”nofollow”>.…

    ñýíêñ çà èíôó!!…

  5. roger    十一月 28 2014 / 9上午:

    cantor@dappertutto.scanty” rel=”nofollow”>.…

    ñïñ….

  6. Lance    十一月 29 2014 / 8下午:

    bradleys@outspoken.caltechs” rel=”nofollow”>.…

    ñïñ!!…

  7. James    十二月 06 2014 / 4下午:

    chauffeured@ladle.kittis” rel=”nofollow”>.…

    ñïñ!…

  8. edgar    十二月 16 2014 / 10上午:

    hoffman@refreshments.lime” rel=”nofollow”>.…

    ñïñ!…

  9. Austin    一月 21 2015 / 12下午:

    broun@vikings.supercilious” rel=”nofollow”>.…

    thanks….

  10. Hector    二月 12 2015 / 8上午:

    calfs@outstanding.tablespoon” rel=”nofollow”>.…

    ñýíêñ çà èíôó!…

  11. Chester    二月 14 2015 / 2下午:

    emperor@brooklyn.bruckners” rel=”nofollow”>.…

    thank you!…

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment