当前位置:首页 » 编程语言 » C语言绘制实心正方形
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

C语言绘制实心正方形

发布时间: 2023-03-05 06:07:54

‘壹’ c程序中,如何让字符按照实心矩形输出,调用函数

c语言程序中,只要输入实心矩形的边长以及构成矩形的字符,就可以使用2重循环,把这个矩形进行输出。
int n,i,j;
char c;
scanf("%d %c",&n,&c);
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
printf("%c",c);
printf("\n");
}
输入数据时,表示边长的数字和字符之间留一个空格。

‘贰’ C语言怎样画正方体

#include <graphics.h>

#include <stdio.h>

#include <conio.h>

#include<math.h>

main()

{

int r,q,w,color;

int gdriver=DETECT,gmode; /*设置图形驱动*/

int Bresenham_Ciecle(); /*定义子函数*/

printf("please input the centre of a circle x0,y0\n");

scanf("%d,%d",&q,&w);

if(q>=320||q<=-320||w<=-250||w>=250)

{printf("please input the centre of a circle again x0,y0\n");

scanf("%d,%d",&q,&w);} /*输入圆心位置越界输出信息*/

printf("please input the numble of radius r=");

scanf("%d",&r);

if(r<=0||r>=500)

{

printf("r is error,r>0,please input the numble of r=");

scanf("%d",&r);

}/*输入半径*/

printf("please input the numble of color=");

scanf("%d",&color);

initgraph(&gdriver,&gmode,"D:\\TC");

setcolor(color);/*设置图形颜色*/

Bresenham_Ciecle(q,w,r,color); /*绘图*/

getch();

}

Bresenham_Ciecle(int q,int w,int r,int color)

{

int x,y,t,v,delta,delta1,delta2,direction;

char buffera[20];

char bufferb[20];

t=getmaxx()/2;

v=getmaxy()/2; /*选定圆心*/

sprintf(buffera, "(%d,%d)", q,w); /*打印圆心坐标*/

sprintf(bufferb, "(0,0) R=%d",r); /*打印原点坐标及半径*/

moveto(t,v+4);

outtext(bufferb); /*圆点坐标定位输出*/

q=q+t;w=v-w;

moveto(q,w);

outtext(buffera);/*原点坐标定位输出*/

line(1,v,2*t,v);

line(t,2*v,t,1);/*画坐标*/

x=q; y=r+w;

line(q, w, x, y); /*画半径*/

delta=2*(1-r);

while(y-w>=0)

{

putpixel(x,y,color); /*右下方1/4个圆*/

putpixel(2*q-x,y,color);/*右上方1/4个圆(从右下方1/4个圆对称复制)*/

putpixel(x,2*w-y,color);/*左下方1/4个圆(从右下方1/4个圆对称复制)*/

putpixel(2*q-x,2*w-y,color);/*左上方1/4个圆(从右下方1/4个圆对称复制)*/

if(delta<0)

{

delta1=2*(delta+y-w)-1;

if(delta1<=0) direction=1;

else direction=2;

}

else if(delta>0)

{

delta2=2*(delta-x+q)-1;

if(delta2<=0) direction=2;

else direction=3;

}

else

direction=2;

switch(direction)

{

case 1: x++;

delta+=2*(x-q)+1;

break;

case 2: x++;

y--;

delta+=2*(1+x-y-q+w);

break;

case 3: y--;

delta+=-2*(y-w)+1;

break;

}

}

}

‘叁’ 用C语言怎样画正方形

根据你的编译器的绘图函数.

有的有绘 rect 函数, (参数,4个角点坐标. 或一个角点坐标和长宽值).
那你用循环语句依次画长宽相等的矩型.

如果只有画直线函数.
那你用循环语句依次调 MoveTo, LineTo 按 角点坐标 画直线.

‘肆’ 用c语言画矩形

每行起始和结束字符均是你的第3个参数
矩形第1行和最后一行中间是第3个参数,其他行根据第4个参数决定是空格或者第3个参数
程序可以这样写:
...
for ( m=0;m<a;m++ )
{
printf("%c",c); //第1列
if ( m==0 || m==a-1 ) //第1行和最后一行
for ( n=1;n<b-1;n++ ) printf("%c",c);
else //中间的行
for ( n=1;n<b-1;n++ ) if ( d==0 ) printf(" "); else printf("%c",c); //空心或否
printf("%c\n",c); //最后1列
}
或者可以写:
for ( m=0;m<a;m++ )
{
printf("%c",c); //第1列
if ( m==0 || m==a-1 || d!=0) for ( n=1;n<b-1;n++ ) printf("%c",c);
else for ( n=1;n<b-1;n++ ) printf(" ");
printf("%c\n",c); //最后1列
}

‘伍’ C语言编写输出图正方形

根据题意可得代码:

#include<stdio.h>
intmain()
{
inti,j;
for(i=0;i<5;++i){
if(i==0||i==4){
for(j=0;j<5;j++){
printf("*");
}
printf(" ");
}
else{
for(j=0;j<5;j++){
if(j==0||j==4)printf("*");
elseprintf("");
}
printf(" ");
}
}
return0;
}

‘陆’ C语言编写一个程序输出一个正方形

思路:输出正方形即输出正方形的外围就行,外围有个特点就是行列下标必有0或者是正方形的大小减一,输入一个n表示正方形大小,输出一个由*组成的正方形。

参考代码:

#include<stdio.h>
intmain()
{
inti,j,n;
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(i==0||i==n-1||j==0||j==n-1)
printf("*");
else
printf("");
}
printf(" ");
}
return0;
}
/*
输出:
5
*****
**
**
**
*****
*/

‘柒’ 用c语言来画1个正方体,一个简单的程序。。

void far bar3d(int x1, int y1, int x2, int y2,int depth,int topflag);当

topflag为非0时, 画出一个三维的长方体。当topflag为0时,三维图形不封顶,

实际上很少这样使用。

void far setfillstyle(int pattern, int color); color的值是当前屏幕图形

模式时颜色的有效值,SOLID_FILL 1 以实填充

void far floodfill(int x, int y, int border);
其中:x, y为封闭图形内的任意一border为边界的颜色,也就是封闭图形轮廓的

颜色。调用了该函数后,将用规定的颜色和图模填满整个封闭图形。

#include<stdlib.h>
#include<graphics.h>
main()
{
int gdriver, gmode;
struct fillsettingstype save;
gdriver=DETECT;
initgraph(&gdriver, &gmode, "");
setbkcolor(BLUE);
cleardevice();
setcolor(LIGHTRED);
setlinestyle(0,0,3);
setfillstyle(1,14); /*设置填充方式*/
bar3d(100,200,400,350,200,1); /*画长方体并填充*/
floodfill(450,300,LIGHTRED);
/*填充长方体另外两个面*/
floodfill(250,150, LIGHTRED);

getch();
closegraph();
}