Archive for 十一月 21st, 2012

21
十一月

程式設計一程式 11/21: 練習6 (ex6.c)

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

#
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void numgen(int num[6]);
int main(int argc, char *argv[])
{
    int i, N;
    int a[6];
    FILE* stream;
 
    //N = atoi(argv[1]);
    //srand( (unsigned) time( NULL ) );
 
    stream=fopen("", "");
    for (i=0; i< N; i++)
    {
        numgen(a);
        printf("%2d %2d %2d %2d %2d %2d\n"
                a[0], a[1], a[2], a[3], a[4], a[5]);
        fprintf(,""
                a[0], a[1], a[2], a[3], a[4], a[5]);
    }
    fclose(stream);
    return 0;
}
void numgen(int num[6])
{
     int i, j, min;
     int select;
     int balls[49];
     for (i=0; i< 49; i++)
     {
         balls[i]=rand();
     }
     for (j=0; j<6; j++)
     {
         select = -1;
         min = RAND_MAX + 1;
         for (i=0; i< 49; i++)
         {
             if (balls[i] < min)
             {
                min    = balls[i];
                select = i;        
             }
         }
         num[j] = select + 1;
         balls[select] = RAND_MAX + 1;
     }
}
 
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,