current position:Home>C language randomly generates 10 addition formulas (the addend is an integer between 1-100, and the sum does not exceed 100), inputs the calculation results of each formula, judges whether the calculation is correct, and outputs the results.

C language randomly generates 10 addition formulas (the addend is an integer between 1-100, and the sum does not exceed 100), inputs the calculation results of each formula, judges whether the calculation is correct, and outputs the results.

2022-01-27 03:35:22 CSDN Q & A

c Language Random generation 10 An addition formula ( The addend is 1-100 Integer between , And no more than 100), Enter the calculation result of each formula , Judge whether the calculation is correct , Output results .




Refer to the answer 1:
#include <iostream>#include <cstdlib>#include <time.h>using namespace std;int main(int argc, char **argv){    uint32_t a, b, sum, value;    for (int i = 0; i < 10; i++) {        srand((unsigned int)time(NULL));        a = rand() % 99;        b = rand() % (100 - a);        sum = a + b;        cout << i + 1 << ": " << a << "+" << b << "=";        cin >> value;        if (value == sum) {            cout << "Right" << endl;        } else {            cout << "Wrong (" << sum << ")" << endl;        }    }}



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270335172175.html

Random recommended