Four yuan (parents no longer have to worry about giving their children a question)
I. Requirements and ideas of Program Design
1. Question
Write a program that can automatically generate the four arithmetic questions of primary school. It requires no less than 30 outputs at a time and can only be four arithmetic operations with an integer of less than 100.
2. Design Philosophy
The two integer variables that output the four arithmetic expressions depend on the random number generation function rand;
An integer less than 100 can be obtained by directly modulo the random number generated except one hundred;
The addition, subtraction, multiplication, division, and division of the four arithmetic operations also depend on random generation. In this way, another variable is set to generate a random number. In addition to the 4 modulo operation, the values 0, 1, 2, and 3 are obtained, implemented using the if condition judgment;
We use a for loop statement to control no less than 30 questions;
For subtraction and division, the subtrahend must be greater than the subtrahend, And the subtrahend must be greater than the subtrahend. Therefore, the if judgment statement must be set to implement control.
Ii. program source code
// This program can randomly generate four arithmetic operations of Integers of less than 100
# Include "stdafx. h"
# Include "stdio. h"
# Include <stdlib. h>
# Include <time. h>
Void disply ()
{
Srand (time (NULL ));
Int I;
For (I = 0; I <30; I ++)
{
Int a = rand () %100;
Int B = rand () %100;
Int c = rand () % 4;
If (c = 0) {printf ("% d + % d = \ n", a, B );}
Else if (c = 1) {printf ("% d * % d = \ n", a, B );}
Else if (c = 2 & a> B) {printf ("% d-% d = \ n", a, B );}
Else if (c = 2 & a <= B) {printf ("% d-% d = \ n", B, );}
Else if (c = 3 & a> B) {printf ("% d/% d = \ n", a, B );}
Else if (c = 3 & a <= B) {printf ("% d/% d = \ n", B, );}
}
}
Void main ()
{
Disply ();
}
Iii. Calculation Result
Iv. Reasons for failure to complete on time
I haven't moved my computer at home for a holiday, let alone programming. When I first heard this question, I only knew there was a random number function, but I didn't know what it was or how to use it, so I got stuck. In addition, I didn't have a good idea of the whole program at the beginning. I started to do it at the beginning. Later I realized that I had to make a good idea after I had to sharpen my knife and cut firewood, well designed, this will be beneficial to future work designation.