• 随机数的加减乘除四则运算(可继续,选择,退出)


    #include "stdio.h"
    #include"windows.h"
    int right=0,wrong=0;
    void add()
    {
      int a,b,c;
      a=rand()%100;
      b=rand()%100;
      printf("请回答:%d+%d=",a,b);
      scanf("%d",&c);
      if(a+b!=c){printf("错误
    ");wrong++;}
      else {printf("正确
    ");right++;} 
    }
    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("错误
    ");wrong++;}
      else {printf("正确
    ");right++;} 
    }
    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("错误
    ");wrong++;}
      else {printf("正确
    ");right++;} 
    }
    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("错误
    ");wrong++;}
      else {printf("正确
    ");right++;} 
    }
    void main()
    {
       int choise,con=0;
       
       printf("
    
    		随机数的四则运算
    "); 
       system("pause");
       system("cls");
       while(1)
       {
        printf("
    
    		请选择:
    加(输入1)
    减(输入2)
    乘(输入3)
    除(输入4)
    "); 
        if(con==0)scanf("%d",&choise);
        switch(choise)
        {
         case 1:add();break;
         case 2:minu();break;
         case 3:mul();break;
         case 4:di();break;
        }
        printf("是否继续或者重新选择运算或者退出程序?
    继续(输入1),重新(输入2),退出(输入3)");
        scanf("%d",&con);
        if(con==1)con=1;
        if(con==2)con=0;
        if(con==3)break;
       }
       printf("您总做了%d个题,正确%d道,错误%d道!
    ",right+wrong,right,wrong);
       system("pause");
    } 


  • 相关阅读:
    几个ID
    一百层高楼和两个棋子
    快速了解的链接 shell sed awk
    用shell实现一个“输入密码”程序
    i love you do you love me
    打造全新视觉环境
    【转】LINUX 环境变量总结
    TextBox输入限制
    获取CPU和硬盘序列号
    Lable属性设置(winform)
  • 原文地址:https://www.cnblogs.com/qijun1120/p/9752147.html
Copyright © 2020-2023  润新知