C Implementation arithmetic 3

Source: Internet
Author: User

Topic:

I chose the topic is to allow the program to accept the user input answers, and determine the right and wrong. Finally, the total number of pairs/errors is given.

Design ideas:

Add a judgment statement after each result if correct, the output is answered correctly and the output is answered incorrectly if the error occurs. The first design time has realized the judgment and error and count, this time will be the first and the second fusion of a bit.

The source code is as follows:

1#include <stdio.h>2#include <stdlib.h>3#include <time.h>4 intMain ()5 {  6     intTiliang,rangeofvalues,ifmuldiv,iffushu,ifyushu,numperhang;7     intx,y,z,temp,result,m=0, rightnumber=0;8printf"Enter the number of tests:");9scanf"%d",&Tiliang);Tenprintf"enter a range of values:"); Onescanf"%d",&rangeofvalues); Aprintf"whether there is a multiplication method (1 indicates that there is, other characters indicate not):"); -scanf"%d",&ifmuldiv); -printf"whether to allow the subtraction result to be negative (1 means allow, other characters are not allowed):"); thescanf"%d",&Iffushu); -printf"The division result has no number (1 means allowed, other characters are not allowed):"); -scanf"%d",&Ifyushu); -  +Srand ((unsigned) time (NULL));//Set seed -      for(intI=0; i<tiliang;i++)//carry out the number of questions cycle +     { AX=rand ()%rangeofvalues;//controlling the range of values atY=rand ()%rangeofvalues; -  -         if(ifmuldiv==1)//control with or without multiplication method -Z=rand ()%4;//randomly appearing according to the value of Z arithmetic -         Else -Z=rand ()%2;  in  -         if(z==0) to         { +printf"%d+%d=", x, y);  -scanf"%d",&result); the             if(result==x+y) *             {                           $printf"that's right,!\n."); Panax Notoginsengrightnumber++;  -             }                          the             Else                          +printf"stupid, wrong!\n.");  A                        the         }   +  -         if(z==1)  $         {    $             if(Iffushu! =1) -             { -temp=x; thex=y; -y=temp;Wuyiprintf"%d-%d=", x, y); thescanf"%d",&result);  -                 if(result==x-y) Wu                 {                              -printf"that's right,!\n.");  Aboutrightnumber++;  $                 }                              -                 Else                           -printf"stupid, wrong!\n.");  -             } A          +             Else the             { -printf"%d-%d=", x, y);  $scanf"%d",&result);  the                 if(result==x-y) the                 {                              theprintf"that's right,!\n.");  therightnumber++;  -                 }                              in                 Else                           theprintf"stupid, wrong!\n.");  the             }              About         }  the  the         if(z==2)  the         { +              while((Ifyushu! =1) && (x%y! =0)) -             { theX=rand ()%rangeofvalues; Bayi             } the              while(y==0) the             { -Y=rand ()%rangeofvalues;  -             } theprintf"%d÷%d=", x, y); thescanf"%d",&result); the             if(result==x/y) the             {                          -printf"that's right,!\n.");  therightnumber++;  the             }                          the             Else                      94printf"stupid, wrong!\n.");  the         }     the          the         if(z==3)98         {     Aboutprintf"%d*%d=", x, y);  -scanf"%d",&result); 101             if(result==x*y)102             {                                   103printf"that's right,!\n."); 104rightnumber++;  the             }                                  106             Else   107printf"stupid, wrong!\n."); 108          }   109     } theprintf"This test was done on the right%d. \ n", rightnumber);111     return 0; the}

The results of the operation are as follows:

Experiment Summary:

This experiment is a combination of the first two experiments, not difficult. Due to my limited strength, if the choice of other topics, it is difficult to publish the blog on time, so chose the first question.

C Implementation arithmetic 3

Related Article

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.