First, design ideas:
1, first the main function is only used to invoke the random generation and output operation problem function, randomly generated and output this part of the function is implemented with a randout function;
2, random generation of the function of the arithmetic, two operations can be generated with random functions, and they are controlled within 100. wherein, considering that the divisor cannot be zero, the second operand is randomly generated +1;
3, the random generation of algorithms this function, the algorithm of a total of 4, you can randomly generate 0-4 of the number, the situation of arithmetic.
Second, the source code:
#include "stdafx.h" #include "stdlib.h" void Randout () //generates a random number and produces a random operation function {int x1,x2; two operands int i,j; for (i=0;i<30;i++) {X1=rand ()%100; X2=rand ()%100+1; The divisor cannot be zero j=rand ()%4; The value of J determines the operation if (j==0) printf ("%d+%d\t\t", x1,x2), if (j==1) printf ("%d-%d\t\t", x1,x2), if (j==2) printf ("%d*%d\t \ t ", x1,x2), if (j==3) printf ("%d/%d\t\t ", x1,x2);} printf ("\ nthe quiz is complete! \ n ");} int _tmain () {printf ("randomly generated 30 operations titled: \ n"); Randout (); Call function return 0;}
Third, the operation result:
Iv. Reasons for Analysis:
1, first see this topic, I think of two arithmetic can be generated with random functions, but the algorithm is unexpectedly how to appear randomly;
2, if only to achieve the arithmetic stochastic and the rules of law appear, the loop is stuck again;
3, the use of random functions, the header file error, and the output is unfamiliar.
Software Engineering class Assignment (i)--randomly generated arithmetic topics