Posts Tagged ‘Lotto Demo’

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: , ,

24
十二月

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

   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
55
package ex10.util.asia;
import java.util.*;
 
public class LottoTicket {
	static Random random = new Random();
	public static void main(String[] args) 
	{
 
		int i,j, nStakeNum=1;
		int[] NumList = new int[6];
		if (args.length>=1)
		{
			nStakeNum=Integer.parseInt(args[0]);
			if (nStakeNum<=0||nStakeNum>5)
			{
				System.out.printf("1~5 stakes one time\n");
				return;
			}
		}
 
		for (i=0; i<nStakeNum; i++)
		{
			LottoNumGen(NumList);
			for (j=0; j< 6; j++)
				System.out.printf("%2d ", NumList[j]);
			System.out.printf("\n");
		}
 
 
	}
	static void LottoNumGen(int List[])
	{
		int i, j;
        int[] number=new int[49];
        int highest, which;
 
        for (i=0; i<49; i++)
        {
            number[i] = random.nextInt();
        }
        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: , ,

24
十二月

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

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

using System;
 
namespace LottoTicket2
{
    class Program
    {
        static Random random = new Random();
        static void Main(string[] args)
        {
            int i,j, nStakeNum=1;
	        int[] NumList =  new int[6];
	        if (args.Length >=1)
	        {
		        nStakeNum=int.Parse(args[0]);
		        if (nStakeNum<=0||nStakeNum>5)
		        {
                    System.Console.WriteLine("1~5 stakes one time");
			        return;
		        }
	        }
 
	        for (i=0; i<nStakeNum; i++)
	        {
		        LottoNumGen(NumList);
		        for (j=0; j< 6; j++)
                    System.Console.Write("{0:00} ", NumList[j]);
                System.Console.WriteLine();
	        }
        }
        static void LottoNumGen(int[] List)
        {
            int i, j;
            int[] number=new int[49];
            int highest, which;
 
            for (i=0; i<49; i++)
            {
                number[i] = random.Next();
            }
            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: , ,