Advertisement
alansam

Multiply

May 18th, 2023
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | Source Code | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. int main(void) {
  7.   /* system(clear); */
  8.   putchar('\n');
  9.  
  10.   srand(time(0));
  11.  
  12.   int a = (rand() % 30) + 1;
  13.   int b = (rand() % 40) + 1;
  14.   int c = 0;
  15.   int sum = 0;
  16.   int ct = 0;
  17.  
  18.   sum = a * b;
  19.   printf("Multiplication programme.\n");
  20.  
  21.   do {
  22.     printf("%d x %d = ", a, b);
  23.     scanf("%d", &c);
  24.     putchar('\n');
  25.  
  26.     if (c == sum) {
  27.       printf("correct\n");
  28.       printf("::: %d x %d = %d\n", a, b, sum);
  29.       printf("=========\n");
  30.     }
  31.     else if (ct++ == 2) {
  32.       printf("the correct answer was: %d x %d = %d\n", a, b, sum);
  33.       break;
  34.     }
  35.     else {
  36.       printf("%d is incorrect.\n", c);
  37.       printf("=========\n");
  38.       printf("try again\n");
  39.     }
  40.   } while (c != sum);
  41.  
  42.   return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement