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