在c++上用图形库graphics.h制作边框
定义一个二维数组,可以把二维数组想想成一个个小的正方形,通过二维数组的下标乘上相应的参数来确定所需要画的正方形的横纵坐标。

#include<iostream>
#include<graphics.h>
#include<conio.h>
using namespace std;
#define M 48
#define N 48
void chessboard()
{
	int chess[M][N];                //定义一个二维数组
	initgraph(480,480);
	setlinecolor(RGB(255,0,0));
	setfillcolor(BROWN);
	int i,j;
	int x,y;                             //定义x,y,来确定画正方形的位置
	for(i=0;i<M;i++)
	{
		for(j=0;j<N;j++)
		{
			if(i==0||j==0||i==(M-1)||j==(N-1))           //将在四条边上的数组元素筛选出来
			{
				chess[i][j]=1;                          //把四条边上的数组元素的值赋值为1
			}
			else
			{
				chess[i][j]=0;
			}
		}

	}
	for(i=0;i<M;i++)
	{
		y=i*10;
		for(j=0;j<N;j++)
		{
			if(chess[i][j]==1)                       //在值为1的地方画正方形。
			{
				x=j*10;
				fillrectangle(x,y,x+10,y+10);
			}

			cout<<chess[i][j]<<"  "<<endl;
		}
		cout<<endl;
	}
	return;
}
int main()
{
	chessboard();
	system("pause");
	return 0;
}

运行效果
在c++上用图形库graphics.h边框

相关文章:

  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2021-09-12
猜你喜欢
  • 2021-11-27
  • 2021-09-19
  • 2021-12-12
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
相关资源
相似解决方案