this program draws random lotto numbers using arrays.
it does make sure the numbers don't repeat.
I want to know how to write it as a 2D array.
heres the code
Thanks in advanceCode:#include <stdio.h> #include <stdlib.h> #include <time.h> #define RANGE 50 #define BALLS 6 int main() { int numbers[RANGE]; int c, ball; puts("L O T T O P I C K E R\n"); srandom((unsigned)time(NULL)); /* initialize array */ for(c = 0; c < RANGE; c++) numbers[c]=0; printf("Press Enter to pick numbers: "); getchar(); /* draw numbers */ puts("Here they come: "); for(c = 0; c < BALLS; c++) { /* see if a number has already been drawn */ do { ball = random() % RANGE; } while(numbers[ball]); /* Number drawn */ numbers[ball] = 1; printf("%d ", ball+1); } printf("\n\nGood luck in the drawing!\n"); return(0); }



LinkBack URL
About LinkBacks




. I learned division with remainders in 4th grade.