以下是程序的代码:

#include <bits/stdc++.h>
#include <windows.h>
#include <graphics.h>
using namespace std;
int num1,num2,lastnum1,lastnum2;//为了解决数字重复问题,定义lastnum去重 
const int SHANGXIAN=100,LIANXISUM=100;//SHANGXIAN是指两个加数的最高数值   LIANXISUM是指练习题的张数 
int x=200,y=600;
int zhengfu; 
int main(){
    //准备界面 
    initgraph(2100,2970);
    setbkcolor(WHITE);
    cleardevice();
    //文本数组定义 
    TCHAR prob[50],biaoti[50];
    //文本颜色处理
    settextcolor(BLACK);
    //随机数
    srand(time(0)); 
    for(int j=1; j<=LIANXISUM; j++){
        //标题处理 
        settextstyle(180,0,_T(""));
        _stprintf(biaoti,_T("练习%d"),j);
        outtextxy(700,300,biaoti);
        //字体变小 
        settextstyle(100,0,_T(""));
        //循环显示算式 
        for(int i=1; i<=30; i++){
            //准备算式 
            num1=rand()%SHANGXIAN+1;
            num2=rand()%SHANGXIAN+1;
            while(1){
                if(num1==lastnum1&&num2==lastnum2){
                    num1=rand()%SHANGXIAN+1;
                    num2=rand()%SHANGXIAN+1;
                }    
                else{
                    break;
                }
            } 
            //正负符号处理 
            zhengfu=rand()%2+1;
            if(zhengfu==1){
                _stprintf(prob,_T("%d+%d="),num1,num2);
            }
            else{
                if(num2>num1){
                    swap(num1,num2);
                }
                _stprintf(prob,_T("%d-%d="),num1,num2);
            }
            //显示 
            outtextxy(x,y,prob); 
            //y坐标增加 
            y+=150; 
            //判断是否换一列
            if(i==15){
                x=1350;
                y=600;
            } 
            //刷新去重变量 
            lastnum1=num1,lastnum2=num2; 
        }
        //缓冲 
        Sleep(50);
        _stprintf(biaoti,_T("lian_%d.png"),j);
        saveimage(biaoti);//截屏
        //重置数据+页面 
        cleardevice();
        x=200,y=600;
    }    
    //截止 
    while(1){}
    /////////
    return 0;
}

效果图:

更多推荐