C语言 矩形填充算法
下面是C语言的矩形填充算法,请问主函数怎么编写?参数怎么传递?给个例子能实现的,谢谢#include"stdio.h"#include"graphics.h"typede...
下面是C语言的矩形填充算法,请问主函数怎么编写?参数怎么传递?给个例子能实现的,谢谢
#include "stdio.h"
#include "graphics.h"
typedef strut
{
int xmin,ymax,ymin,ymax;
}Rectangle;
void FillRectangle(Rectangle *rect,int color)
{
int x,y;
for(y = rect->ymin;y<=rect->ymax;y++)
for(x = rect->xmin;x<=rect->xmax;x++);
putpixel(x,y,color);
}/* end of FillRectangle() */ 展开
#include "stdio.h"
#include "graphics.h"
typedef strut
{
int xmin,ymax,ymin,ymax;
}Rectangle;
void FillRectangle(Rectangle *rect,int color)
{
int x,y;
for(y = rect->ymin;y<=rect->ymax;y++)
for(x = rect->xmin;x<=rect->xmax;x++);
putpixel(x,y,color);
}/* end of FillRectangle() */ 展开
1个回答
展开全部
#include <stdio.h>
#include <graphics.h>
typedef struct {
int xmin, xmax, ymin, ymax;
} Rectangle;
void FillRectangle(Rectangle *rect, int color) {
int x = 0, y = 0;
for (y = rect->ymin; y <= rect->ymax; y++)
for (x = rect->xmin; x <= rect->xmax; x++) //这里有个分号,应该去掉。
putpixel(x, y, color);
}/* end of FillRectangle() */
int main() {
//declare our color
int color = 0;
//declare our rectangle
Rectangle *rect = (Rectangle *) malloc(sizeof(Rectangle));
if(NULL == rect )
{
printf("allocation memory failed!\n");
return 1;
}
//input the scope
printf("Enter the x-min:\n");
scanf("%d", &rect->xmin);
printf("Enter the x-max:\n");
scanf("%d", &rect->xmax);
printf("Enter the y-min:\n");
scanf("%d", &rect->ymin);
printf("Enter the y-max:\n");
scanf("%d", &rect->ymax);
//input the color
printf("Enter your color:\n");
scanf("%d", &color);
//call our paint function
FillRectangle(rect, color);
return 0;
}
#include <graphics.h>
typedef struct {
int xmin, xmax, ymin, ymax;
} Rectangle;
void FillRectangle(Rectangle *rect, int color) {
int x = 0, y = 0;
for (y = rect->ymin; y <= rect->ymax; y++)
for (x = rect->xmin; x <= rect->xmax; x++) //这里有个分号,应该去掉。
putpixel(x, y, color);
}/* end of FillRectangle() */
int main() {
//declare our color
int color = 0;
//declare our rectangle
Rectangle *rect = (Rectangle *) malloc(sizeof(Rectangle));
if(NULL == rect )
{
printf("allocation memory failed!\n");
return 1;
}
//input the scope
printf("Enter the x-min:\n");
scanf("%d", &rect->xmin);
printf("Enter the x-max:\n");
scanf("%d", &rect->xmax);
printf("Enter the y-min:\n");
scanf("%d", &rect->ymin);
printf("Enter the y-max:\n");
scanf("%d", &rect->ymax);
//input the color
printf("Enter your color:\n");
scanf("%d", &color);
//call our paint function
FillRectangle(rect, color);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询