这两天做了很多随机函数的用法(下面是一个出题实验)。

#include "stdio.h"
#include "stdlib.h"
#include "time.h"
main()
{
    int a,b,c,x,d,f=0,g=0;
        srand((unsigned)time(NULL));
        a=rand()%1000+1;
        b=rand()%1000+1;
        printf("请选择题目
1.1-1000的加法运算
2.1-1000的减法运算
3.1-1000的乘法运算
4.1-1000的除法运算
5.退出答题
");
        scanf("%d",&x);
        system("cls");
    while(g<=10)
    {
     
        if(x==1)
        {    
            d=a+b;
            printf("%d+%d=",a,b);
        
        }
        else if(x==2)
        {    
            d=a-b;
            printf("%d-%d=",a,b);
        }
        else if(x==3)
        {    
            d=a*b;
            printf("%d*%d=",a,b);
        }
        else if(x==4)
        {    
            d=a/b;
            printf("%d/%d=",a,b);
        }
        else
        {
            printf("按任意键退出!");    break;
        }
        scanf("%d",&c);
            if(c==d)
            {   
                f=f+10;
                printf("恭喜你,答对了!您的分数是%d分
",f);
            }
            else 
            {   
                f=f-10;
                printf("很遗憾,答错了!您的分数是%d分
",f); 
            }
            g++;
    }
}
原文地址:https://www.cnblogs.com/doublekai/p/6012683.html