Four yuan (parents no longer have to worry about giving their children a question)

Source: Internet
Author: User

Four yuan (parents no longer have to worry about giving their children a question)

I. Requirements and ideas of Program Design

1. Question

Write a program that can automatically generate the four arithmetic questions of primary school. It requires no less than 30 outputs at a time and can only be four arithmetic operations with an integer of less than 100.

2. Design Philosophy

The two integer variables that output the four arithmetic expressions depend on the random number generation function rand;

An integer less than 100 can be obtained by directly modulo the random number generated except one hundred;

The addition, subtraction, multiplication, division, and division of the four arithmetic operations also depend on random generation. In this way, another variable is set to generate a random number. In addition to the 4 modulo operation, the values 0, 1, 2, and 3 are obtained, implemented using the if condition judgment;

We use a for loop statement to control no less than 30 questions;

For subtraction and division, the subtrahend must be greater than the subtrahend, And the subtrahend must be greater than the subtrahend. Therefore, the if judgment statement must be set to implement control.

Ii. program source code

// This program can randomly generate four arithmetic operations of Integers of less than 100

# Include "stdafx. h"
# Include "stdio. h"
# Include <stdlib. h>
# Include <time. h>
Void disply ()
{
Srand (time (NULL ));
Int I;
For (I = 0; I <30; I ++)
{
Int a = rand () %100;
Int B = rand () %100;
Int c = rand () % 4;
If (c = 0) {printf ("% d + % d = \ n", a, B );}
Else if (c = 1) {printf ("% d * % d = \ n", a, B );}
Else if (c = 2 & a> B) {printf ("% d-% d = \ n", a, B );}
Else if (c = 2 & a <= B) {printf ("% d-% d = \ n", B, );}
Else if (c = 3 & a> B) {printf ("% d/% d = \ n", a, B );}
Else if (c = 3 & a <= B) {printf ("% d/% d = \ n", B, );}
}
}
Void main ()
{
Disply ();
}

Iii. Calculation Result

Iv. Reasons for failure to complete on time

I haven't moved my computer at home for a holiday, let alone programming. When I first heard this question, I only knew there was a random number function, but I didn't know what it was or how to use it, so I got stuck. In addition, I didn't have a good idea of the whole program at the beginning. I started to do it at the beginning. Later I realized that I had to make a good idea after I had to sharpen my knife and cut firewood, well designed, this will be beneficial to future work designation.

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.