Hi, 1st time poster.
I'm currently working on a program that generates random numbers 1-49. I want to sort them from lowest to highest, how would i come about doing that?
here's what i got so far
Thanks in advance!Code:#include <stdio.h> #include <stdlib.h> #include <time.h> //for the seedrnd() function #define RANGE 49 //number of numbers #define BALLS 7 //number of balls to draw #define DELAY 1000000 //delay interval between picks int rnd(int range); char loop; void seedrnd(void); void main() { do { int numbers[RANGE]; //array that holds the balls int i,b; unsigned long d; //delay variable seedrnd(); //seed the randomizer /* initialize the array */ for(i=0;i<RANGE;i++) //initialize the array numbers[i]=0; printf("Press Enter to pick this week's numbers:"); getchar(); /* draw the numbers */ for(i=0;i<BALLS;i++) { for(d=0;d<=DELAY;d++); //pause here /* picks a random number and check to see whether it's already been picked */ do { b=rnd(RANGE); //draw number } while(numbers[b]); //already drawn? numbers[b]=1; //mark it as drawn printf(" %i ",b+1); //add one for zero } printf("\n Press 1 to return"); scanf("%d", &loop); } while (loop==1); } /* Generate a random value */ int rnd(int range) { int r; r=rand()%range; //spit up random number return(r); } /* Seed the randomizer */ void seedrnd(void) { srand((unsigned)time(NULL)); }