Topic:
- Automatically generate arithmetic topics
Basic requirements:
- In addition to integers, you can support the arithmetic of true fractions.
- Describes the functionality that is implemented and the requirements for implementing the results.
Programming Environment:
- This programming uses the C language, the programming software uses is the C-FREE5.
Main functions:
- The user enters the required number of topics, and the program automatically generates the required number of arithmetic topics (which include the subtraction operations of integers and true fractions).
Design ideas:
- First, when you see the topic, because the program automatically generates numbers, it is necessary for the rand () function to randomly generate various numbers for the factor, while the random subtraction four symbols also need to be selected using random functions.
- Because there are four operation symbols, switch () is required to select them.
- Because of the need for fractions, random numbers require 4, each of which is synthesized by a fraction of 2.
- In the design, in order to simplify the problem, it is convenient to calculate, the greatest common divisor of the numerator denominator of the fraction is calculated by using the calling function, then the fractional fraction is calculated.
Program Run code:
1#include"stdio.h"2#include"stdlib.h"3#include"time.h"4 5 intMaxintAintb)6 {7 intk,l,p;8 if(A<B) {l=a;a=b;b=l;}9 while(b!=0)Ten { Onek=a%b;a=b;b=K; A } -p=A; - returnp; the - } - Main () - { + inta,b,c,d,t,k,m,p; - int*P1; +Srand ((int) Time (NULL)); Aprintf"Please enter the desired number of questions \ t"); atscanf"%d",&k); - for(intI=0; i<k;i++) - { -A=rand ()% -+1; -B=rand ()% -+1; -C=rand ()% -+1; inD=rand ()% -+1; -T=rand ()%8; to Switch(t) + { - Case 0:p rintf ("%d +%d=\n", A, b); Break; the Case 1:{ * if(A<B) {m=a,a=b,b=m;} $printf"%d-%d=\n", A, b); Break;Panax Notoginseng } - Case 2:p rintf ("%dx%d=\n", A, b); Break; the Case 3:p rintf ("%d÷%d=\n", A, b); Break; + Case 4:{ A if(A>B) {m=a,a=b,b=m;} the if(c>d) {m=c,c=d,d=m;} +a=a/Max (A, b); -b=b/Max (A, b); $c=c/Max (c,d); $d=d/Max (c,d); -printf"%d/%d +%d/%d=\n", a,b,c,d); Break; - } the Case 5:{ - if(A>B) {m=a,a=b,b=m;}Wuyi if(c>d) {m=c,c=d,d=m;} thea=a/Max (A, b); -b=b/Max (A, b); Wuc=c/Max (c,d); -d=d/Max (c,d); Aboutprintf"%d/%d-%d/%d=\n", a,b,c,d); Break; $ } - Case 6:{ - if(A>B) {m=a,a=b,b=m;} - if(c>d) {m=c,c=d,d=m;} Aa=a/Max (A, b); +b=b/Max (A, b); thec=c/Max (c,d); -d=d/Max (c,d); $printf"%d/%dx%d/%d=\n", a,b,c,d); Break; the } the Case 7:{ the if(A>B) {m=a,a=b,b=m;} the if(c>d) {m=c,c=d,d=m;} -a=a/Max (A, b); inb=b/Max (A, b); thec=c/Max (c,d); thed=d/Max (c,d); Aboutprintf"%d/%d÷%d/%d=\n", a,b,c,d); Break; the } the } the } + return 0; -}
Program run:
Summarize:
This assignment I think is relatively simple, in the beginning of the design, only the integer subtraction operation, only used 3 rand () function (2 factors of random, 1 symbols random), and then use switch to output different symbols between the subtraction of the formula. After adding a fraction of the operation, and then appear the design of the first problem, the score is not a parameter, resulting in the original output statement is not able to output a+b= such a formula, so I think of adding more case, to add the calculation of the score, but there is a problem, case too many, Cause the program to complicate, I have not thought of a better solution. Finally, in the test I found that the score is not a real score, and can be numerator, I will be the fraction of the simplification and the denominator than the numerator of such a limit to add to the program, into the current program.
This program is not very perfect, there are a lot of places to add and improve, I hope that later I can improve the ability to design a more practical, more concise program out.
Job Two: Personal programming Project--arithmetic