• 四则运算


    #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;
    }

  • 相关阅读:
    SQL Server 查看物理页存储
    Sql Server 孤立用户解决办法
    大文件下载
    UITableViewCell
    xib文件的使用
    UIToolbar
    UIView常见的属性和方法
    iOS的三种多线程技术:
    网络处理文件上传、获取文件MIMEType、其他HTTP请求方式
    转场动画过渡效果
  • 原文地址:https://www.cnblogs.com/dearqiqi/p/8550984.html
Copyright © 2020-2023  润新知