
程序代码:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
    srand((unsigned)time(NULL));
    char flag[4]={'+','-','*','/'};
    printf("下面开始随机出题:\n");
    int i;
    int j;
    char k;
    char n;
    int m;
    while(1)
    {
        i=rand()%1000;
        j=rand()%1000;
        k=rand()%4;
        if (k==0)
        {
            printf("%d  %c  %d = ",i,flag[k],j);
            scanf("%d",&m);
            if(m==i+j) printf("结果正确\n");else printf("错误的计算结果\n");
        }
        fflush(stdin);
        if (k==1)
        {
            printf("%d  %c  %d = ",i,flag[k],j);
            scanf("%d",&m);
            if(m==i-j) printf("结果正确\n");else printf("错误的计算结果\n");
        }
        fflush(stdin);
        if (k==2)
        {
            printf("%d  %c  %d = ",i,flag[k],j);
            scanf("%d",&m);
            if(m==i*j) printf("结果正确\n");else printf("错误的计算结果\n");
        }
        if (k==3)
        {
            //这里是除法的相关代码 由于涉及到除0问题和浮点问题 所以不写了
        }
        fflush(stdin);
        printf("继续做题不?(y or n)");
        scanf("%c",&n);
        if(n=='n' || n=='N') break;
        fflush(stdin);
    }
    return 0;
}
/*
我的测试案例:
下面开始随机出题:
40  -  164 = -124
结果正确
继续做题不?(y or n)y
418  -  63 = 5
错误的计算结果
继续做题不?(y or n)y
683  +  73 = 756
结果正确
继续做题不?(y or n)y
437  *  980 = 8569
错误的计算结果
继续做题不?(y or n)y
641  -  788 = -147
结果正确
继续做题不?(y or n)y
679  *  299 = 36258
错误的计算结果
继续做题不?(y or n)
*/
[
 本帖最后由 wp231957 于 2015-6-22 20:06 编辑 ]