Software Engineering class Assignment (i)--randomly generated arithmetic topics

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.