please dont rip this site

language ccpp cref PROBLEMS lotto2

/ ************************************************************************
 *
 * Purpose: Second crack at a lottery number selector.
 * Author:  M.J. Leslie.
 * Date:   03-Dec-94
 * Description: Any 6 random numbers from 1 to 49 are displayed. 
 *              Duplicates are removed and the results sorted.
 *
 ************************************************************************/

/********** Preprocessor  ***********************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define NUMBERS 6

/********** Functions ***************************************************/

void display_nums(int *, int);
int comp_nums(const int *, const int *);

/************************************************************************/
main()
   {
   int num[NUMBERS];			/* array holding the selected
					 * numbers			*/
   int count;				/* General  counter		*/
		

   printf("\n\nLOTTERY CRACKER V1.1\n");
   printf("--------------------\n\n");
   printf("\tPossible winning ticket number is ");

					/* New starting point
					 * for the random number generator.
					 */

   srand((unsigned int)time((time_t *)NULL));

					/* Collect Six numbers.	
					 * Filter out duplicats as we go.
					 */
   {
   int dup, count2;
   for (count=0; count < NUMBERS; count++) 
      {
      num[count]=(rand()%49)+1;		/* Get a number.		*/
      dup=0; 				/* Set the duplicate flag to 
					 * NO DUPLICATES		*/
					/* Test latest number with the ones
				 	 * already held.		*/
      for (count2=0 ; count2 < count; count2++)
         {
					/* If match found - set flag.	*/
         if (num[count] == num[count2]) dup++ ;
         }
					/* If flag set - reset the array
					 * index so we overwrite the current
					 * number.			*/
      if (dup > 0 ) count--;
      }
   }
					/* Sort the numbers		*/
   qsort(
	num, 				/* Pointer to elements		*/
	NUMBERS, 			/* Number of elements		*/
	sizeof(int),  			/* size of one element.		*/
	(void *)comp_nums		/* Pointer to comparison function */
	);

   display_nums(num, NUMBERS); 		/* Display the results		*/
   }

/************************************************************************
 *
 * comp_nums: Compare two numbers.
 *
 ************************************************************************/

int comp_nums(const int *num1, const int *num2)
   {
   return (*num1 - *num2);
   }

/************************************************************************
 *
 * display_nums: Display the numbers
 *
 ************************************************************************/

void display_nums(int *array, int count)
   {
					/* Print all the elements of 
					 * the array.               	*/
   while ( count-- ) 
      {
      printf("%d ",*array);
      array++;
      }
   puts("");
   puts("");
   }


file: /Techref/language/ccpp/cref/PROBLEMS/lotto2.c, 2KB, , updated: 1997/4/21 09:53, local time: 2012/5/23 21:44,
TOP NEW HELP FIND: 
38.107.179.231:LOG IN

 ©2012 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF="http://www.piclist.com/tecHREF/language/ccpp/cref/PROBLEMS/lotto2.c"> language ccpp cref PROBLEMS lotto2</A>

Did you find what you needed?

 
Stepper motors CAN be smooth!
And stepper controllers can be strong and cheap. Roman Black's Linistep stepper controller kits:
o 18th microstep
o Linear smoothing
  o Open source
o Full kit $25!
 
miSim DE is an excellent, portable and powerful IDE for developing PIC applications.
The only consistant, simple to use yet powerful development environment. It simulates real-world devices via virtual component "plugins" (LED,LCD,key,motor,TV,etc) in real time, has a syntax highlighting editor, macro assembler and disassembler. Regular updates and third-party plugins keep this software ahead of any other PIC IDE.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .