Job two: Automatically generate arithmetic

Source: Internet
Author: User

Main function: This program can generate arithmetic automatically, there is the choice of algorithms and the ability to view the answer.
Design ideas: You can choose the algorithm, you can randomly appear calculation questions, can appear the answer, you can also directly into the next question.
Source:
#include <stdio.h>#include<stdlib.h>#include<time.h>Main () {inta,b,op,os;aq1:printf ("Choose the algorithm you want to challenge \ n");p rintf ("1. Addition 2. Subtraction 3. Multiplication 4. Division \ n"); scanf ("%d",&op);Switch(OP) {aq: Case 1: Srand ((unsigned) time (NULL)); a=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d +%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d +%d =%d\n\n\n", a,b,a+b);Gotoaq1;}ElseGotoaq; Break; at: Case 2: A=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d-%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d-%d =%d\n\n\n", a,b,a-b);Gotoaq1;}ElseGotoat ; Break; AQ2: Case 3: A=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d *%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d *%d =%d\n\n\n", a,b,a*b);Gotoaq1;}ElseGotoaq2;aq3: Case 4: A=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d/%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d/%d =%d\n\n\n", a,b,a/b);Gotoaq1;}ElseGotoaq3; Break;}}
Run:
Summary: This time to do is still very immature, do when there are a lot of errors, referring to the same type of online program, only to find the wrong place, in the reference to the online program, the idea is gradually opened, after the finished look at their own procedures, there is a sense of accomplishment, very rewarding, I believe in the next study, I will reap more.

Job two: Automatically generate arithmetic

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.