Second week continued. (Code)

Source: Internet
Author: User

#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)

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.