猜一下矩阵中的数字

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int random(int m, int n);

int main() {//
  int try1, maxTries, numProblems, answer, response;
  int num1, num2;

  numProblems = 5;
  maxTries = 5;

  srand(time(0));

  for (int h = 1; h <= numProblems; h++) {
    num1 = random(10, 99);
    num2 = random(10, 99);
    answer = num1 + num2;
    for (try1 = 1; try1 <= maxTries; try1++) {
      printf(\nProblem %d, Try %d of %d\n, h, try1, maxTries);
      printf(%5d + %2d = , num1, num2);
      scanf(%d, &response);
      if (response == answer) {
        printf(Correct, well done!\n);
        break;
      }
      if (try1 < maxTries)
        printf(Incorrect, try again\n);
      else
        printf(Sorry, answer is %d\n, answer);
    }
  }
}

int random(int m, int n) {
  int offset = rand() / (RAND_MAX + 1.0) * (n - m + 1);
  return m + offset;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。