Source:
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#include <time.h>
int main ()
{
int a = 0;
int b = 0;
int mode = 0;//0: plus 1: minus 2: Multiply by 3: except
int i = 0;
int c[5]={0,30,1,100,1};//whether to customize, the number of question, whether there is multiplication, the upper limit, the lower value.
Srand ((unsigned) time (NULL)); Initializes the random number generator so that the random number generated for each run is different
printf ("Are you customizing? is input 1, no input 0: ");
cin>>c[0];
if (c[0]==0)
{
for (i=0;i<30;i++)//Do 30 questions
{
A = rand ()% 100; Generates a random number between 0~99
b = rand ()% 100; Generates a random number between 0~99
mode = rand ()% 4; Generates a random number between 0~3, which represents the operator
printf ("%d", a); Print calculation
switch (mode)//OK operator
{
Case 0:
printf ("+%d = \ n", b);
Break
Case 1:
printf ("-%d = \ n", b);
Break
Case 2:
printf ("*%d = \ n", b);
Break
Case 3:
printf ("/%d = \ n", b);
Break
Default
printf ("Somethingis wrong!\n");
Break
}
}
}
else {
cout<< "Please enter the number of question:";
cin>>c[1];
cout<< "Does it contain multiplication? is input 1, no input 0: ";
cin>>c[2];
cout<< "Value upper limit:";
cin>>c[3];
cout<< "Lower value:";
cin>>c[4];
for (i=0;i<c[1];i++)//Custom problem number
{
A = rand ()% (c[3]-c[4]+1) +c[4]; Generate a qualified random number
b = rand ()% (c[3]-c[4]+1) +c[4]; Generate a qualified random number
if (c[2]==1) {
mode = rand ()% 4; Generates a random number between 0~3, which represents the operator
printf ("%d", a); Print calculation
switch (mode)//OK operator
{
Case 0:
printf ("+%d = \ n", b);
Break
Case 1:
printf ("-%d = \ n", b);
Break
Case 2:
printf ("*%d = \ n", b);
Break
Case 3:
printf ("/%d = \ n", b);
Break
Default
printf ("Somethingis wrong!\n");
Break
}
}
else{
mode = rand ()% 2; Generates a random number between 0~3, which represents the operator
printf ("%d", a); Print calculation
switch (mode)//OK operator
{
Case 0:
printf ("+%d = \ n", b);
Break
Case 1:
printf ("-%d = \ n", b);
Break
Default
printf ("Somethingis wrong!\n");
Break
}
}
}
}
return 0;
}
Run:
New arithmetic topics C + +