The specific requirements are as follows:
- can automatically generate primary school arithmetic topic (note is for the pupils, if the results appear negative, they will be confused!) )
- In addition to integers, support the arithmetic of true fractions
Implementation of the scenario:
1. Automatically generate primary arithmetic topic, the first need to generate two random numbers, where RAND (), in order to ensure that the random number within 100, and avoid 0, so rand ()%100+1;
2. Use the switch case statement to randomly select the subtraction operation and invoke the corresponding sub-function;
3. The addition operation is divided into two cases: the first two addend are integers. A>b, direct output a+b=? Two. There is a case of true scores. When A<b and e<f, output A/b + f =?;
4. The subtraction operation is divided into four kinds of cases: first, the meiosis and meiosis are all integers and a>b, the direct output a-b=? Two. If there is a true score and a<b e<f, output A/b-e/f=?; Three. A<b and e>f, output b-a=?; iv. a/b<e/f, output e/f-a/b=?;
5. The multiplication operation is divided into two cases: the first two multipliers are integers. A>b, direct output a*b=? Two. There is a case of true scores. When A<b and e<f, output A/b */f =?;
6. Division operation in two cases: first, the divisor, the divisor is an integer and a>b, the direct output of a/b=? Two. There is a case of true scores. When A<b and e<f, output A/b/f =?;
Problems encountered in programming: Put the Srand () function inside the for loop, causing all occurrences of the random number to be equal, after checking the corrected data to meet the requirements.
List of programs:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void Add (int a,int b,int e,int f) {
if (a>b)
printf ("%d +%d=?\n", A, b);
if (a < b&&e<f)
printf ("%d/%d +%d/%d=?\n", A, B, E, f);
}
void Jian (int a,int b,int e,int f) {
if (a>b)
printf ("%d-%d=?\n", A, b);
if (a < b) {
if (e>f)
printf ("%d-%d=?\n", B, a);
Else
{
if (float (a)/float (b) > float (e)/float (f))
printf ("%d/%d-%d/%d=?\n", A, B, E, f);
Else
printf ("%d/%d-%d/%d=?\n", E, F, A, b);
}
}
}
void Cheng (int a,int b,int e,int f) {
if (a>b)
printf ("%d *%d=?\n", A, b);
if (a < b&&e<f)
printf ("%d/%d *%d/%d =?\n", A, B, E, f);
}
void Chu (int a,int b,int e,int f) {
if (a>b)
printf ("%d/%d=?\n", A, b);
else{
if (e>f)
printf ("%d/%d=?\n", B, a);
Else
printf ("%d/%d/%d/%d=?\n", A, B, E, f);
}
}
int main () {
int A, b,c,d,e,f;
printf ("Please enter the number of questions: \ n");
scanf ("%d", &d);
Srand ((unsigned) time (NULL));
for (int i = 0; i < D; i++) {
A = rand ()% 100+1;
b = rand ()% 100+1;
c = rand ()% 4;
e = rand ()% 100 + 1;
f = rand ()% 100 + 1;
Switch (c) {
Case 0:
Add (A, b,e,f);
Break
Case 1:
Jian (A, b,e,f);
Break
Case 2:
Cheng (A, b,e,f);
Break
Case 3:
Chu (A, b,e,f);
Break
}
}
printf ("Enter any number to end!") \ n ");
scanf ("%d", &d);
return 0;
}
First time job