Title: Automatic generation of arithmetic topics
Main function: Can be generated in addition to integers, support true score arithmetic, generate a problem, the problem is random.
Design ideas: First of all, I start with the simplest part of writing, and will need to generate 8 kinds of possible problems to write the format of the basic code is as follows:
#include <stdio.h>intMain () {inta,b,x,y,; printf ("%d+%d=\n", A, b);p rintf ("%d-%d=\n", A, b);p rintf ("%d*%d=\n", A, b);p rintf ("%d/%d=\n", A, b);p rintf ("%d/%d+%d/%d=\n", A,x,b,y);p rintf ("%d/%d-%d/%d=\n", A,x,b,y);p rintf ("%d/%d*%d/%d=\n", A,x,b,y);p rintf ("%d/%d/%d/%d=\n", a,x,b,y);}
After writing the above code, run, you will find that the value of the four number of a,b,x,y is very large, so I chose to define the size of the value, rand () statement to define the size of the value, although you can simply write rand () to define the value of the size of the code, But in the writing program random occurrences of the place, encountered trouble, the beginning of the program I write only fixed generated a value, has been 1/7-= this topic, where I met the bottleneck, in addition to their basic knowledge is not firm, so start, I refer to the Internet, mainly Baidu know the main, Look at the problems that others have encountered while writing this program, and find a basic framework for getting started.
Reference pages:
Http://zhidao.baidu.com/link?url=wKnpo3-cgxWvaEfToguP3pdLzNX4hsT1n70TWgjuSjdInjISfFXaoTVIq4WjD30V_qY0_HKTNYHA9GVuhWDp-q
On this page, I saw in the nice people who answered, so that the program can randomly generate the required number of statements
#include <time.h>srand ((unsigned) time (NULL)); for (i=0;i<; i++)
Reference, this page gives the framework, after the modification of its own program will eventually complete the overall program to generate a random number of questions and the program.
Source:
#include<stdio.h>
#include <stdlib.h>#include <time.h>
intMain () {inta,b,x,y,i; Srand ((unsigned) time (NULL)); for(i=0;i<1; i++); {a=rand ()% -; b=rand ()% -; X=rand ()% -; Y=rand ()% -; I=rand ()%7; Switch(i) { Case 0:p rintf ("%d+%d=\n", A, b); Break; Case 1:p rintf ("%d-%d=\n", A, b); Break; Case 2:p rintf ("%d*%d=\n", A, b); Break; Case 3:p rintf ("%d/%d=\n", A, b); Break; Case 4:p rintf ("%d/%d+%d/%d=\n", a,x,b,y); Break; Case 5:p rintf ("%d/%d-%d/%d=\n", a,x,b,y); Break; Case 6:p rintf ("%d/%d*%d/%d=\n", a,x,b,y); Break; Case 7:p rintf ("%d/%d/%d/%d=\n", a,x,b,y); Break;} } }
Program run:
Summarize:
Through this assignment, I harvest a lot, because their foundation is not very good, so, some code can say do not know, through this writing the topic generation program, let me learn a lot of new code, the most profound is to write randomly generated the number of code:
#include <time.h> srand ((unsigned) time (NULL)); for 0; J < i;j++)
Also realize that only repeated practice, can really master the language used, after a freshman C language learning, to now has been a long time useless, there are a lot of knowledge points have been forgotten, I also good review of the previous knowledge. This programming work, I learned that many of their shortcomings, and some other students to learn better than, I should learn from them, with more time to practice the programming language more, in fact, although the work I completed, but there are many needs to improve the place, see other students to make up the program, but also added a new question and answer system, Some can also enter the number of questions required, randomly generate the number of questions required, in the class, I will look at these people to make up the program, see how these features are realized, and learn from themselves. The programming language knowledge that this homework uses, I also will practise more, thoroughly grasp it to understand.
Automatically generate arithmetic topics