Created
April 10, 2018 07:53
-
-
Save AungWinnHtut/b0c2bdbc80f8796a5fba624c76fbd165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This program is to draw a rectangle with printf and for loops | |
to train for looping especially | |
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> | |
void drawRectangle(int x1, int y1, int w, int h, char ch); | |
int main() | |
{ | |
drawRectangle(6,4,10,8,'$'); | |
getch(); | |
drawRectangle(3,3,6,11,'*'); | |
getch(); | |
drawRectangle(7,1,22,4,'0'); | |
getch(); | |
return 0; | |
} | |
void drawRectangle(int x1, int y1, int w, int h, char ch) | |
{ | |
system("cls"); | |
//move down to y axis till y1 | |
for(int y=1;y<=y1;y++) | |
{ | |
printf("\n",y); | |
} | |
//print roll by roll | |
for(int roll=1;roll<=h;roll++) | |
{ | |
//move right to x axis till x1 | |
for(int x=1;x<=x1;x++) | |
{ | |
printf(" ",x); | |
} | |
//print left border with width 1 char | |
printf("%c",ch); | |
//print inner width-2*border | |
//if top and botton print * for border | |
//else print space for hollow | |
if((roll==1)||(roll==h)) | |
{ | |
for(int c=1;c<=w-2;c++) | |
{ | |
printf("%c",ch); | |
} | |
} | |
else | |
{ | |
for(int c=1;c<=w-2;c++) | |
{ | |
printf(" "); | |
} | |
} | |
//print right boundary | |
printf("%c",ch); | |
//new line to print next roll | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment