It took almost half an hour to do this program. From the beginning of the idea to the practice of the statement, there have been some grammatical errors, and finally has been amended. Because the language of learning is limited (C # just began to learn, big moment to learn C language), here choose to write this program in C, the environment is vs2010.
Outline and ideas for writing software:
1. Need to generate random natural numbers, I chose the RAND function
2. Need to have a subtraction symbol and random distribution, I define a random number C, when the random number of 0 is the +, take 1 of the time is-, take 2 is *, take 3 of the time is/
3. The number of subtraction can not be negative, I used the IF function to determine the size, if the order is not suitable for two random numbers to exchange
4.30 questions can be easily generated with a For loop statement
The code is as follows:
#include <stdio.h>#include<Windows.h>#include<time.h>voidMain () {intA, B, C, D, I; Srand (Unsigned (Time (NULL))); for(i =0; I < -; i++) {a= rand ()% -; b= rand ()% -; C= rand ()%4; Switch(c) { Case 0:p rintf ("%d +%d =\n", A, b); Break; Case 1:if(A <b) {d=A; A=b; b=D; } printf ("%d-%d =\n", A, b); Break; Case 2:p rintf ("%d *%d =\n", A, b); Break; Case 3: while(b = =0) {b= rand ()% -; } printf ("%d/%d =\n", A, b); Break; }} system ("Pause");}
The results of the operation are as follows:
Compared to the program, the random function rand is used to obtain the random number, using the FOR function to control the number of questions generated. The difference is that the "+-*/" notation is generated, I define a random variable C, its range is 0-3, by the number of C generated to determine the subtraction symbol, and the classmate is to define a string containing subtraction, and then use Srand to get the random operator inside. Overall, the results are the same, I also learned another programming method, a lot of harvest.
Individual Item 1: A "software" that can generate the second-grade arithmetic topic in primary school