chess board – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sun, 21 Aug 2022 07:06:41 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg chess board – Programmerbay https://programmerbay.com 32 32 C Program to Draw Chess Board https://programmerbay.com/program-to-draw-a-chess-board-in-c/ https://programmerbay.com/program-to-draw-a-chess-board-in-c/#respond Fri, 12 Aug 2022 07:47:11 +0000 https://www.programmerbay.com/?p=2108 C supports a special header file named graphics.h that provides various functions through which one can draw different shapes such as line, circle, triangle, and more. And with the combination of these functions, we can create objects like a hut, joker, cap, and more.

The program draws a Chess board with the help of graphic libraries. It uses rectangle(), setcolor(), floodfill and setfillstyle() functions to draw this object.

C program to Draw Chess Board

 Program:

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main(){
int gr=DETECT,gm;
int row,col,x=50,y=50,flag=0;
initgraph(&gr,&gm,"C:\\TURBOC3\\BGI");
printf("\t*********** CHESS BOARD **************\n");
for(row=0;row<8;row++)
{

for(col=1;col<=8;col++){
if(flag==0){
setcolor(YELLOW);
setfillstyle(SOLID_FILL,BLACK);
rectangle(x,y,x+50,y+50);
floodfill(x+1,y+1,YELLOW);
flag=1;
}
else
{
setcolor(YELLOW);
setfillstyle(SOLID_FILL,WHITE);
rectangle(x,y,x+50,y+50);
floodfill(x+1,y+1,YELLOW);
flag=0;
}
x=x+50;
}
if(flag==0)
flag=1;
else
flag=0;
delay(100);
x=50;
y=50+y;
}
getch();
closegraph();
}

 

Output:

chessboard

]]>
https://programmerbay.com/program-to-draw-a-chess-board-in-c/feed/ 0