Individual Item 1: A "software" that can generate the second-grade arithmetic topic in primary school

Source: Internet
Author: User

It took almost half an hour to do this program. From the beginning of the idea to the practice of the statement, there have been some grammatical errors, and finally has been amended. Because the language of learning is limited (C # just began to learn, big moment to learn C language), here choose to write this program in C, the environment is vs2010.

Outline and ideas for writing software:

1. Need to generate random natural numbers, I chose the RAND function

2. Need to have a subtraction symbol and random distribution, I define a random number C, when the random number of 0 is the +, take 1 of the time is-, take 2 is *, take 3 of the time is/

3. The number of subtraction can not be negative, I used the IF function to determine the size, if the order is not suitable for two random numbers to exchange

4.30 questions can be easily generated with a For loop statement

The code is as follows:

#include <stdio.h>#include<Windows.h>#include<time.h>voidMain () {intA, B, C, D, I;    Srand (Unsigned (Time (NULL)));  for(i =0; I < -; i++) {a= rand ()% -; b= rand ()% -; C= rand ()%4; Switch(c) { Case 0:p rintf ("%d +%d =\n", A, b);  Break;  Case 1:if(A <b) {d=A; A=b; b=D; } printf ("%d-%d =\n", A, b);  Break;  Case 2:p rintf ("%d *%d =\n", A, b);  Break;  Case 3:             while(b = =0) {b= rand ()% -; } printf ("%d/%d =\n", A, b);  Break; }} system ("Pause");}

The results of the operation are as follows:

Compared to the program, the random function rand is used to obtain the random number, using the FOR function to control the number of questions generated. The difference is that the "+-*/" notation is generated, I define a random variable C, its range is 0-3, by the number of C generated to determine the subtraction symbol, and the classmate is to define a string containing subtraction, and then use Srand to get the random operator inside. Overall, the results are the same, I also learned another programming method, a lot of harvest.

Individual Item 1: A "software" that can generate the second-grade arithmetic topic in primary school

Related Article

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.