training

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

elementar.c (608B)


      1 /* Exercise 5.32 */
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <time.h>
      6 
      7 int main()
      8 {
      9    int n1 = 1 + rand() % 9;
     10    int n2 = 1 + rand() % 9;
     11    int num;
     12 
     13 
     14    while(1) {
     15       srand( time(NULL) );
     16 
     17       printf("How much is %d times %d?\n", n1, n2);
     18       printf("Answer (%d to end): ", EOF);
     19       scanf("%d", &num);
     20 
     21       if(num == EOF)
     22 	 break;
     23 
     24       printf("\n");
     25       if(num == n1 * n2) {
     26 	 printf("Very good!");
     27 	 n1 = 1 + rand() % 9;
     28 	 n2 = 1 + rand() % 9;
     29       }
     30       else
     31 	 printf("No. Please try again.");
     32       printf("\n\n");
     33    } /* end while (num) */
     34 
     35    return 0;
     36 } /* E0F main */
     37