#include "stdafx.h" #include<stdio.h> #include<stdlib.h> #include<string.h> #include<time.h> #include <math.h> void Jiaf(); void jianf(); void CF(); void Chuf(); void GJ(); int i; void main() {int choose;While (1) {printf ("===================================\n"); printf ("Welcome to use this program please select function: \ n"); printf ("1 simple addition 2 simple subtraction \ n"); printf ("3 simple multiplication 4 simple division \ n"); printf ("5 Advanced algorithm \ n"); printf ("Please enter your choice (1--5):"); scanf ("%d", &choose); switch (choose){case 1:jiaf (); break; case 2:jianf (); break; case 3:CF (); break; case 4:chuf (); break; case 5:gj (); break; }}}void jiaf() {int a,b,c,h;Srand ((unsigned) time (0)); printf ("\ n addition problem:"); For (int i=0;i<2;i++) {printf (""); A=rand ()%;printf ("%d", a); B=rand ()%;printf ("+"); printf ("%d", b); printf ("="); H=a+b;scanf ("%d", &c); if (c==h){printf ("\ n answer right!") ");}Elseprintf ("\ n answer the wrong! ");printf ("\ n"); }}void jianf() {int a,b,c,h;Srand ((unsigned) time (0)); printf ("\ n subtraction:"); For (i=0;i<2;i++) {printf (""); A=rand ()%;printf ("%d", a); B=rand ()%;printf ("-"); printf ("%d", b); printf ("="); H=a-b;scanf ("%d", &c); if (c==h){printf ("\ n answer right!") ");}Elseprintf ("\ n answer the wrong! ");printf ("\ n"); }}void CF() {int a,b,c,h;Srand ((unsigned) time (0)); printf ("\ n multiplication question:"); For (i=0;i<2;i++) {printf (""); A=rand ()%Ten;printf ("%d", a); B=rand ()%Ten;printf ("*"); printf ("%d", b); printf ("="); H=a*b;scanf ("%d", &c); if (c==h){printf ("\ n answer right!") ");}Elseprintf ("\ n answer the wrong! ");printf ("\ n"); }}void Chuf() {int A, b;float c,h;Srand ((unsigned) time (0)); printf ("\ n Division question (two decimal places after result retention):"); For (i=0;i<2;i++) {printf (""); A=rand ()%Ten;printf ("%d", a); B=rand ()%Ten;While (b==0) {B=rand ()%Ten;}printf ("/"); printf ("%d", b); printf ("="); H= (A *1.0)/b;H= ((float) ((int) ((H +0.005) * ))/scanf ("%f", &c); if (c==h){printf ("\ n answer right!") ");}Elseprintf ("\ n answer the wrong! ");printf ("\ n"); }}void GJ() {int p;int l,a,b,c,h,k;Srand ((unsigned) time (0)); P=rand ()%Ten;if (p>5) {p=0;}Elsep=1;switch (p){Case 0: A=rand ()%Ten;P=rand ()%Ten;if (p>5) {p=0;}Elsep=1;switch (p){Case 0: B=rand ()%Ten;C=rand ()%Ten;printf ("(%d+%d) *%d=", a,b,c); H= (a+b) *c;scanf ("%d", &k); if (k==h){printf ("\ n answer right!") ");}Elseprintf ("\ n answer the wrong! ");printf ("\ n"); break; case 1: B=rand ()%Ten;C=rand ()%Ten;printf ("(%d-%d) *%d=", a,b,c); H= (A-B) *c;scanf ("%d", &k); if (k==h){printf ("\ n answer right!") ");}Elseprintf ("\ n answer the wrong! ");printf ("\ n"); break; }Break ;case 1:a=rand ()% ; B=rand ()%Ten;C=rand ()%Ten;printf ("%d* (%d+%d) =", a,b,c); h=a* (B+C);scanf ("%d", &k); if (k==h){printf ("\ n answer right!") ");}Elseprintf ("\ n answer the wrong! ");printf ("\ n"); break; }}
Second week continued. (Code)