20150324 exercise a program with four arithmetic questions, and 20150324 arithmetic operations

Source: Internet
Author: User

20150324 exercise a program with four arithmetic questions, and 20150324 arithmetic operations

Source code:

# Include <stdio. h>
# Include <stdlib. h>
Main ()
{Int a, B, op, OS;
Printf ("[do not worry about my learning when I practice every lesson] \ n ");
Aq1: printf ("select the algorithm you want to challenge \ n ");
Printf ("1. Addition 2. subtraction 3. Multiplication 4. Division \ n ");
Scanf ("% d", & op );
Switch (op)
{
Aq: case 1:
A = rand (); B = rand ();
Printf ("Question: % d + % d =? \ N ", a, B );
Printf ("1. view the answer 2. Make the next question \ n ");
Scanf ("% d", & OS );
If (OS = 1)
{Printf ("% d + % d = % d \ n", a, B, a + B );
Goto aq1;
}
Else
Goto aq;
Break;
At: case 2: a = rand (); B = rand ();
Printf ("Question: % d-% d =? \ N ", a, B );
Printf ("1. view the answer 2. Make the next question \ n ");
Scanf ("% d", & OS );
If (OS = 1)
{Printf ("% d-% d = % d \ n", a, B, a-B );
Goto aq1;
}
Else
Goto;
Break;
Aq2: case 3:
A = rand (); B = rand ();
Printf ("Question: % d * % d =? \ N ", a, B );
Printf ("1. view the answer 2. Make the next question \ n ");
Scanf ("% d", & OS );
If (OS = 1)
{Printf ("% d * % d = % d \ n", a, B, a * B );
Goto aq1;
}
Else
Goto aq2;
Aq3: case 4:
A = rand (); B = rand ();
Printf ("Question: % d/% d =? \ N ", a, B );
Printf ("1. view the answer 2. Make the next question \ n ");
Scanf ("% d", & OS );
If (OS = 1)
{Printf ("% d/% d = % d \ n", a, B, a/B );
Goto aq1;
}
Else
Goto aq3;
Break;
}
}

Summary:

1. rand () does not actually implement srand.

2. Excessive goto use causes damage to the overall structure

3. No rand range is set.

 

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.