zoukankan      html  css  js  c++  java
  • 四则运算

    首先要感谢各位同学的,尤其是吴阿平同学的帮助和耐心讲解。

    感觉到自己编写代码的能力实在是有待加强,需要长时间的积累和磨练。

    #include<stdio.h>
    #include<math.h>
    #include<windows.h>
    int right=0;
    int 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("回答正确! ");
    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("出错!请重新输入! ");
    }

  • 相关阅读:
    solr6.5搭建以及使用经验
    Intellij IDEA svn的使用记录
    初次从eclipse转到intellij idea上的一些经验
    Linux一键安装PHP/JAVA环境OneinStack
    CentOS下yum安装mysql,jdk以及tomcat
    centos yum换阿里云源
    ehcache配置:使用Spring+SpringMVC+Mybatis或者有shiro
    微博短链接的生成算法(Java版本)
    手把手教你使用Git
    工作中有关分布式缓存的使用和需要注意的问题梳理
  • 原文地址:https://www.cnblogs.com/hushihui666/p/5285568.html
Copyright © 2011-2022 走看看