Title: Automatic generation of arithmetic of 100 or less, and support of arithmetic of true score;
According to the requirements of the topic, the decision to use the random number function Srand (), rand () function to generate the operand, rand ()%100 can produce a number within 100. Rand ()% 4来 produces a 0~3 of four numbers to select arithmetic.
#include <stdio.h>
#include <time.h>
#include <Windows.h>
#include <stdlib.h>
void Main ()
{
int A, b,c,d,i,op,x;
Srand (Unsigned (Time (NULL)));
printf ("Please select type: \n1 integer arithmetic; \n2 true score arithmetic; \ n");
scanf ("%d", &x);
Switch (x)
{
Case 1:
{
for (i = 0; i <; i++)
{
A = rand ()% 100;
b = rand ()% 100;
op = rand ()% 4;
if (op = = 0)
printf ("%d +%d =\n", A, b);
else if (op = = 1 && a>b)
printf ("%d-%d =\n", A, b);
else if (op = = 2)
printf ("%d *%d =\n", A, b);
else if (op = = 3 && b! = 0)
printf ("%d÷%d =\n", A, b);
}
Break
}
Case 2:
{
for (i = 0; i <; i++)
{
A = rand ()% 100;
b = rand ()% 100;
while (b==0)
b = rand ()% 100;
c = rand ()% 100;
while (c==0)
c = rand ()% 100;
d = rand ()% 100;
while (d==0)
d = rand ()% 100;
if (A < b && C < D)
{
op = rand ()% 4;
if (op = = 0)
printf ("%d/%d +%d/%d =\n", A, B, C, D);
else if (op = = 1 && (A/b) >= (C/D))
printf ("%d/%d-%d/%d =\n", A, B, C, D);
else if (op = = 2)
printf ("%d/%d *%d/%d =\n", A, B, C, D);
else if (op = = 3)
printf ("%d/%d÷%d/%d =\n", A, B, C, D);
}
else i--;
}
Break
}
}
System ("pause");
}
Program Run Result:
The program basically satisfies the topic request, can choose the integer operation or the true fractional operation according to the need.
But because the academic is not fine, the procedure is not concise. It takes half a day.
During programming, you encounter a black box flashback problem, ask the classmate, online find by adding head function #include<windows.h>, and freeze screen system ("pause") problem solved. In the process of true fractional operation, if for two operands, the count variable I also increases when the operation condition is not satisfied, and the number of the program running result is not enough. By the Else statement, the i--is executed when the condition is not met, and the problem is resolved. The program does not consider the fractional operation when the score can be numerator, for the user's calculation to increase the workload, but also the user's ability to calculate the training bar!
It is hoped that the ability can be improved by programming training.
The procedure and problems of pupils ' 300 exercises