Archive for 十月, 2013

1023prog

產生樂透的模擬資料檔案

產生樂透的模擬資料檔案

 

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

23
十月

程式設計一程式 10/23: ex6.c

   Posted by: admin    in 102(上)程式設計(一)

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void NumGen(int num[]);
int main(int argc, char *argv[])
{
    int i, tickets;
    int num[6];
    FILE* out;
    tickets = atoi(argv[1]);
    srand( (unsigned) time( NULL ) );//設定亂數的啟始點
 
    out = fopen("lotto.txt", "w");
    for (i=0; i< tickets; i++)
    {
        NumGen(num);
        printf("%2d %2d %2d %2d %2d %2d\n", num[0], num[1], num[2], num[3], num[4], num[5]);
        fprintf(out "%2d %2d %2d %2d %2d %2d\n", num[0], num[1], num[2], num[3], num[4], num[5]);
    }
    fclose(out);
    return 0;
}
void NumGen(int num[])
{
    int i,j, max, select;
    int ball[49];
    for (i= 0; i< 49; i++)
    {
        ball[i] = rand();
    }
 
    for (i= 0; i< 6; i++)
    {
        select = 0//選擇的球 
        max = ball[0]//最重的球
        for (j = 1; j < 49; j)
        {
            if (ball[j]  max)
            {
                  max =  ball[j];  
                  select = j;  
            } 
        } 
       num[i] = select +1;//最重的那顆球編號 
            ball[select] = 0;
    }
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

1022mim

RIS/CIS

RIS/CIS

住院醫囑的種類

住院醫囑的種類

醫療資訊的發展趨勢

醫療資訊的發展趨勢

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

1016prog

陣列變數和亂數的使用

陣列變數和亂數的使用

演算法

演算法

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{
    int i, num[6];
 
    srand( (unsigned) time( NULL ) );//設定亂數的啟始點
 
    for (i= 0; i< 6; i++)
    {
        num[i] = rand() % 49 + 1;  
    }
 
    printf("%2d %2d %2d %2d %2d %2d", num[0], num[1], num[2], num[3], num[4], num[5]);
    return 0;
}
============================
for (i= 0; i< 49; i++)
    {
        ball[i] = rand();
    }
 
 
    for (i= 0; i< 6; i++)
    {
        select = 0;//選擇的球 
        max = ball[0];//最重的球
        for (j = 1; j < 49; j++)
        {
            if (ball[j] > max)
            {
                  max =  ball[j];  
                  select = j;  
            } 
        } 
 
        num[i] = select +1;//最重的那顆球編號 
        ball[select] = 0;
    }

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,