zoukankan      html  css  js  c++  java
  • 20150324 练习1 四则运算题目的程序

    源代码:

    #include<stdio.h>
    #include<stdlib.h>
    main()
    {int a,b,op,os;
    printf(" [每课一练 妈妈再也不用担心我的学习]\n");
    aq1: printf("选择您想挑战的运算法则\n");
    printf("1.加法 2.减法 3.乘法 4.除法\n");
    scanf("%d",&op);
    switch(op)
    {
    aq: case 1:
    a=rand();b=rand();
    printf("题目为:%d + %d = ?\n\n",a,b);
    printf("1.查看答案 2.做下一题\n");
    scanf("%d",&os);
    if(os==1)
    {printf("%d + %d =%d\n\n\n",a,b,a+b);
    goto aq1;
    }
    else
    goto aq;
    break;
    at: case 2:a=rand();b=rand();
    printf("题目为:%d - %d = ?\n\n",a,b);
    printf("1.查看答案 2.做下一题\n");
    scanf("%d",&os);
    if(os==1)
    {printf("%d - %d =%d\n\n\n",a,b,a-b);
    goto aq1;
    }
    else
    goto at;
    break;
    aq2: case 3:
    a=rand();b=rand();
    printf("题目为:%d * %d = ?\n\n",a,b);
    printf("1.查看答案 2.做下一题\n");
    scanf("%d",&os);
    if(os==1)
    {printf("%d * %d =%d\n\n\n",a,b,a*b);
    goto aq1;
    }
    else
    goto aq2;
    aq3: case 4:
    a=rand();b=rand();
    printf("题目为:%d / %d = ?\n\n",a,b);
    printf("1.查看答案 2.做下一题\n");
    scanf("%d",&os);
    if(os==1)
    {printf("%d / %d =%d\n\n\n",a,b,a/b);
    goto aq1;
    }
    else
    goto aq3;
    break;
    }
    }

    总结:

    1.rand()涵数没有真正实现随 用srand会更好

    2.过多的goto使用 使整体结构破坏

    3.没有设置rand的范围

  • 相关阅读:
    重写保存按钮save事件
    隐藏列获取不到值,表格选中行提示未选中
    前后台获取上下文context
    editGrid分录表格
    通用查询-高级查询
    js保留位和取整
    在Visual Studio中使用C++创建和使用DLL
    Lua中的一些库(1)
    Lua中的面向对象编程
    Lua中的模块与包
  • 原文地址:https://www.cnblogs.com/kasion/p/4363486.html
Copyright © 2011-2022 走看看