自动生成小学四则运算题目(加强版)

#include <stdio.h>
main()
{
    int i,x,y,z,number,result,input,total=0,times;
    int accuracy;
    srand(time(NULL));
    printf("请输入出题的数目:(除数结果取整数)");
    scanf("%d",&number);
    printf("题目有%d题,总分共%d分
",number,number*10);
    for(i=1;i<=number;i++)
    {
        times=2;
        x=rand()%100+1; //产生随机数x为第一位数
        y=rand()%100+1; //产生随机数y为第二位数
        z=(x+y)%4; //z用来确定随机产生的运算符号
        if(z==0) //输出算术式
        {
            printf("%d:%d+%d=",i,x,y);
            result=x+y;
        }
        if(z==1)
        {
            printf("%d:%d-%d=",i,x,y);
            result=x-y;
        }
        if(z==2)
        {
            printf("%d:%d*%d=",i,x,y);
            result=x*y;
        }
        if(z==3)
        {
            printf("%d:%d/%d=",i,x,y);
            result=x/y;
        }
        do
        {
        scanf("%d",&input);
        if(input==result)
        {
            printf("恭喜你答对了!
");
            total=total+10;
        }
        else
        {
            if(times!=0)
                printf("很遗憾答错了!你还有%d次机会!
",times);
            else
                printf("很遗憾答错了!本题答题结束!
");
            times=times-1;
        }
        }while(input!=result&&times!=-1);
    }
    accuracy=total/(number*10);
    printf("本次答题,你获得的分数为%d,正确率为%d%%!
",total,accuracy);
    if(accuracy<60)
        printf("不合格!请多加练习!
");
    else if(accuracy<80)
        printf("你的水平有待提高!
");
    else
        printf("你的水平不错!
");
}
原文地址:https://www.cnblogs.com/SshengS/p/4384077.html