zoukankan      html  css  js  c++  java
  • 简单的四则运算(续)

    这个程序是给出复杂的四则运算,包含两个运算符的。

    #include<stdio.h>
    int sum = 0;
    struct NUM3
    {
        int one;
        int two;
        int three;
        int result;
    }stu2[400];
    int complex();
    int show() 
    {
        printf("谢谢使用");
    
    }
    void main()
    {
        int a=1;
        while (a == 1)
        {
            a = complex();
        }
        show();
    }
    int complex()
    {
        int a, b, c,m;
        int s[10];
        for (int i = 0; i < 10; i++)
        {
            a = stu2[sum].one = rand() % 10 + 1;
            b = stu2[sum].two = rand() % 10 + 1;
            c = stu2[sum].three = rand() % 10 + 1;
            int n = rand() % 4 + 1;//stu2[sum].result = a*b + c;
            switch (n)
            {
                case 1: stu2[sum].result = a*b + c;
                        printf("%d*%d+%d=	", a, b, c); break;
                case 2: stu2[sum].result = a + b * c;
                        printf("%d+%d*%d=	", a, b, c); break;
                case 3: stu2[sum].result = a*b - c;
                        printf("%d*%d-%d=	", a, b, c); break;
                case 4: stu2[sum].result = a - b * c;
                        printf("%d-%d*%d=	", a, b, c); break;
                
                }
            sum = sum + 1;
        }
        printf("请输入上面十题的答案
    ");
        for (int i = 0; i < 10; i++)
        {
            printf("%d.",i+1);
            scanf_s("%d",&s[i]);
        }
        for (int i = 0; i < 10; i++)
        {
            if (s[i] == stu2[i].result)
            {
                printf("");
            }
            else{
                printf("第%d题错误,正确答案是%d", i+1, stu2[i].result);
            }
        }
        printf("继续请按1,结束请按任意键");
        scanf_s("%d",&m);
        if (m == 1)
            return 1;
        else
            return 0;
    }

    下面是程序运行截图:

  • 相关阅读:
    函数指针与变长参数列表
    Finding intersection and union of two sets.
    依赖注入
    可达性分析算法
    java 虚拟机栈
    Java 堆
    java虚拟机>>程序计数器
    Java方法区(Method Area)
    Java 运行时常量池
    java引用
  • 原文地址:https://www.cnblogs.com/shenpfei/p/5272084.html
Copyright © 2011-2022 走看看