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

    #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>
    int main()
    {
        int a,b,c,i,d;
        srand((time(NULL)));
        for(i=0;i<20;i++)
        {
        a=rand()%100;
        b=rand()%100;
        c=rand()%4;

            switch(c)
            {
        case 0:
            printf("%d+%d= ",a,b);
            printf("请输入正确答案: ");
            int e;
            scanf("%d",&e);
            if(a+b==e)
            printf("恭喜您回答正确! ");
            else
                printf("您回答错误,正确答案是%d ",a+b);
            break;
        case 1:
            if(a<b)
            {
                d=a;
                a=b;
                b=d;
            }
            printf("%d-%d= ",a,b);
            printf("请输入正确答案: ");
            int f;
            scanf("%d",&f);
            if(a-b==f)
                printf("恭喜您回答正确! ");
            else
                printf("您回答错误,正确答案是%d ",a-b);
            break;

        case 2:
            printf("%d*%d= ",a,b);
            printf("请输入正确答案: ");
            int g;
            scanf("%d",&g);
            if(a*b==g)
                printf("恭喜您回答正确! ");
            else
                printf("您回答错误,正确答案是%d ",a*b);
            break;
        case 3:
            if(a*b==0)
            {
                a++;
                b++;
                if(a%b==0)
                {
                     printf("%d/%d= ",a,b);
                     printf("请输入正确答案: ");
                     int h;
            scanf("%d",&h);
            if(a/b==h)
                printf("恭喜您回答正确! ");
            else
                printf("您回答错误,正确答案是%d ",a/b);
            break;
                }
                else
                    {
                        a++;
                        while(a%b!=0)
                        {
                              a++;
                        }
                        printf("%d/%d= ",a,b);
                              printf("请输入正确答案: ");
                        int j;
                        scanf("%d",&j);
                        if(a/b==j)
                            printf("恭喜您回答正确! ");
                        else
                            printf("您回答错误,正确答案是%d ",a/b);

                    }

            }
            else
            {
                if(a%b==0)
                {
                     printf("%d/%d= ",a,b);
                     printf("请输入正确答案: ");
                     int i;
            scanf("%d",&i);
            if(a/b==i)
                printf("恭喜您回答正确! ");
            else
                printf("您回答错误,正确答案是%d ",a/b);
            break;
                }
                else
                    {
                        a++;
                        while(a%b!=0)
                        {
                              a++;
                        }
                        printf("%d/%d= ",a,b);
                              printf("请输入正确答案: ");
                        int k;
                        scanf("%d",&k);
                        if(a/b==k)
                            printf("恭喜您回答正确! ");
                        else
                            printf("您回答错误,正确答案是%d ",a/b);

                    }

            }


           }
        }
    return 0;
    }

  • 相关阅读:
    01--DNS服务器3
    01--DNS服务器2
    装配bean
    实现二级域名
    apache反向代理
    struts拓展restful
    restful是什么
    struts的声明式异常处理
    linux常用命令之压缩打包
    linux常用命令之文件系统
  • 原文地址:https://www.cnblogs.com/dearqiqi/p/8550984.html
Copyright © 2011-2022 走看看