training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

intgroup.c (456B)


      1 /* Esercizio 5.14 */
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <time.h>
      6 
      7 int main()
      8 {
      9    int i;
     10 
     11    srand( time(NULL) );
     12 
     13    /* 2 4 6 8 10 */
     14    while((i = 2 + rand() % 10) % 2) ;
     15    printf("2 4 6 8 10: %d\n", i);
     16 
     17    /* 3 5 7 9 11 */
     18    while( !( (i = 3 + rand() % 9) % 2) ) ;
     19    printf("3 5 7 9 11: %d\n", i);
     20 
     21    /* 6 10 14 18 22 */
     22    while( (i = 6 + rand() % 17) % 4 != 2) ;
     23    printf("6 10 14 18 22: %d\n", i);
     24 
     25    return 0;
     26 } /* E0F main */
     27