zoukankan      html  css  js  c++  java
  • 随机数的加减乘除四则运算(可继续,选择,退出)

    #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");
    } 


  • 相关阅读:
    bzoj2101:[USACO2010 DEC]TREASURE CHEST 藏宝箱
    P3976 [TJOI2015]旅游(未完成)
    洛谷 P 5 3 0 4 [GXOI/GZOI2019]旅行者
    NOIP原题 斗地主(20190804)
    P2860 [USACO06JAN]冗余路径Redundant Paths
    vue中的插槽(slot)
    vue动态绑定class
    发现一个ps抠毛发简单快捷高质量的方法
    propsData传递数据
    sort排序原理
  • 原文地址:https://www.cnblogs.com/qijun1120/p/9752147.html
Copyright © 2011-2022 走看看