• 四则运算 来自 http://www.cnblogs.com/ys1101/p/4368103.html


    #include<stdio.h>
    #include<math.h>
    #include<windows.h>
    int right=0;
    int wrong=0;
    void add()
    {
     int a,b,c,d;
     a=rand()%100;
     b=rand()%100;
     printf("请回答:
    		 %d + %d = ",a,b);
     scanf("%d",&c);
     if(a+b==c)
     {
      printf("回答正确!
    ");
      right++;
     }
     else
     {
      printf("回答错误!
    ");
      wrong++;
     }
    }
    void minu()
    {
     int a,b,c;
     a=rand()%100;
     b=rand()%100;
     printf("请回答:
    		 %d - %d = ",a,b);
     scanf("%d",&c);
     if(a-b==c)
     {
      printf("回答正确!
    ");
      right++;
     }
     else
     {
      printf("回答错误!
    ");
      wrong++;
     }
    }
    void mul()
    {
     int a,b,c;
     a=rand()%100;
     b=rand()%100;
     printf("请回答:
    		 %d * %d = ",a,b);
     scanf("%d",&c);
     if(a*b==c)
     {
      printf("回答正确!
    ");
      right++;
     }
     else
     {
      printf("回答错误!
    ");
      wrong++;
     }
    }
    void di()
    {
     int a,b,c;
     a=rand()%100;
     b=rand()%100;
     printf("请回答:
    		 %d / %d = ",a,b);
     scanf("%d",&c);
     if(a/b==c)
     {
      printf("回答正确!
    ");
      right++;
     }
     else
     {
      printf("回答错误!
    ");
      wrong++;
     }
    }
    void main()
    {
     int choise;
     int con=0;
     printf("
    			欢迎进入小学简易四则运算
    
    ");
     while(1)
     {
      printf("请选择:
    ");
      printf("			  加法运算(请输入1)
    ");
      printf("			  减法运算(请输入2)
    ");
      printf("			  乘法运算(请输入3)
    ");
      printf("			  除法运算(请输入4)
    ");
      printf("			  退出运算(请输入5)
    ");
      if(con==0)
       scanf("%d",&choise);
      switch(choise)
      {
      case 1:
       add();
       break;
      case 2:
       minu();
       break;
      case 3:
       mul();
       break;
      case 4:
       di();
       break;
      case 5:
       return;
      }
      printf("
    			继续运算?(请输入1)
    ");
      printf("
    			重新选择?(请输入2)
    ");
      printf("
    			退出运算?(请输入3)
    ");
      scanf("%d",&con);
      if(con==1)
       con=1;
      else if(con==2)
       con=0;
      else if(con==3)
       break;
      else
       printf("抱歉!,你输入的指令有误!请重新输入!
    ");
     }
     printf("您总共完成了 %d 道题
    正确 %d 道
    错误 %d 道
    ",right+wrong,right,wrong);
    }

     

  • 相关阅读:
    Leetcode 笔记 110
    Leetcode 笔记 100
    Leetcode 笔记 99
    Leetcode 笔记 98
    Leetcode 笔记 101
    Leetcode 笔记 36
    Leetcode 笔记 35
    Leetcode 笔记 117
    Leetcode 笔记 116
    android加载速度优化,通过项目的优化过程分析
  • 原文地址:https://www.cnblogs.com/blueland/p/7559925.html
Copyright © 2020-2023  润新知