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的范围

  • 相关阅读:
    熟悉常用的Linux操作
    Python基础综合练习
    简易c语言文法
    词法分析程序
    组合数据类型综合练习
    综合练习:词频统计
    词法分析程序2
    我对编译原理的理解
    【分享】博客美化(6)为你的博文自动添加目录
    python爬虫的基本思路
  • 原文地址:https://www.cnblogs.com/kasion/p/4363486.html
Copyright © 2011-2022 走看看