四则运算

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main()
{
    int a,b1,b2,i,f,g,x;
    double c1,c2,c,d;
    srand(time(NULL));
    do{
        printf("输入1生成题目,输入其他退出程序");
        scanf("%d",&x);
        getchar();
        if(x==1)
        {
            b1=rand()%100;
            b2=rand()%100;
            i=rand()%4;
            switch(i)
            {
                case 1:
                {
                    printf("%d+%d=",b1,b2);
                    c=b1+b2;
                    break;
                }
                case 2:
                {
                    printf("%d-%d=",b1,b2);
                    c=b1-b2;
                    break;
                }
                case 3:
                {
                    printf("%d*%d=",b1,b2);
                    c=b1*b2;
                    break;
                }
                case 4:
                {
                    printf("(结果保留两位小数)%d/%d=",b1,b2);
                    c1=b1;
                    c2=b2;
                    c=c1/c2;
                    break;
                }
            }
            f=c*100;
            scanf("%lf",&d);
            getchar();
            g=d*100;
            if(f==g)printf("正确!");
            else printf("错误!");
            printf("

");
        }
    }while(x==1);
}
原文地址:https://www.cnblogs.com/SiPine/p/4370124.html