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

  • 相关阅读:
    C语言中标识符的作用域、命名空间、链接属性、生命周期、存储类型
    循环练习
    ArrayList集合

    方法
    表单标签
    HTML基础
    二维数组
    一维数组
    switch选择结构
  • 原文地址:https://www.cnblogs.com/kasion/p/4363486.html
Copyright © 2011-2022 走看看