Skip to content

Instantly share code, notes, and snippets.

@AungWinnHtut
Created April 10, 2018 04:58
Show Gist options
  • Save AungWinnHtut/bff819c79707580bdb54e3b5e0b61fad to your computer and use it in GitHub Desktop.
Save AungWinnHtut/bff819c79707580bdb54e3b5e0b61fad to your computer and use it in GitHub Desktop.
This program is to draw a rectangle with printf and for loops to train looping and coordinate calculation for two days beginner in C
/*
This program is to draw a rectangle with printf and for loops
to train looping and coordinate calculation
for two days beginner in C
Programmer: Dr. Aung Win Htut (Green Hackers)
https://www.facebook.com/GreenHackersOTC/
Date: 10-04-2018
*/
#include<stdio.h>
#include<conio.h>
#include<process.h>
int funDrawRectangle(int x, int y, int d,char ch);
int main()
{
for(int i=5,j=5;i<20,j<20;i++,j++)
{
funDrawRectangle(i,j,8,'*');
getch();
}
return 0;
}
int funDrawRectangle(int x, int y, int d,char ch)
{
int r=d/2;
system("cls");
for(int k=1;k<=y-r-1;k++)
{
printf("\n");
}
for(int j=y-r;j<=y+r;j++)
{
for(int i=1;i<=x-r-1;i++)
{
printf(" ",ch);
}
for(int i=x-r;i<=x-r;i++)
{
printf("%c",ch);
}
for(int i=x-r+1;i<=x+r-1-1;i++)
{
if((j==y-r)||(j==y+r))
{
printf("%c",ch);
}
else
{
printf(" ");
}
}
for(int i=x+r;i<=x+r;i++)
{
printf("%c",ch);
}
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment