20160310 first question

Source: Internet
Author: User

Title: Automatic generation of arithmetic

Main function: Realize arithmetic

Design ideas: Randomly appear subtraction arithmetic, answer, the system automatically judge right and wrong, press ENTER to display the next question, press 0 to exit.

Source:

#include <stdio.h>#include<time.h>#include<stdlib.h>intMain () {inta,b,c,d,s; intx1=0, x2=0; printf ("--------arithmetic------\ n");  while(1) {Srand (Time (NULL)); D=a=rand ()% -; b= (rand ()%a+a)% -; if(a%4==1&&a<b) {c=a,a=b,b=C; }       if(b==0&&a%4==3) {b=rand ()%Ten+1; }       if(a%4==3&&a%b!=0) {Srand (0)); A=b* (rand ()%a); }      Switch(d%4)      {        Case 0:p rintf ("%d +%d =", A, b); scanf ("%d",&c); if(c==a+b) {printf ("That's correct! \ n"); X1++; }          Else{printf ("wrong answer! \ n"); X2++; } Break;  Case 1:p rintf ("%d-%d =", A, b); scanf ("%d",&c); if(c==a-b) {printf ("That's correct! \ n"); X1++; }          Else{printf ("wrong answer! \ n"); X2++; } Break;  Case 2:p rintf ("%dx%d =", A, b); scanf ("%d",&c); if(c==a*b) {printf ("That's correct! \ n"); X1++; }          Else{printf ("wrong answer! \ n"); X2++; } Break;  Case 3:p rintf ("%d÷%d =", A, b); scanf ("%d",&c); if(c==a/b) {printf ("That's correct! \ n"); X1++; }          Else{printf ("wrong answer! \ n"); X2++; } Break; } printf ("Press Enter to continue, press 0 to exit the challenge! \ n");      Fflush (stdin); if(GetChar () = ='0') Break; }         return 0;}

Program run:

Summarize:

This program combined with some of the online code, plus some of their own changes merged. Through this programming, I found that the previous learning things are basically forgotten, so it seems that the future is still more practice, can not be put down.

20160310 first question

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.