Created
March 22, 2011 09:20
-
-
Save iamben/880970 to your computer and use it in GitHub Desktop.
square.c
This file contains 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
#include <stdio.h> | |
int main(int argc, const char *argv[]) | |
{ | |
int width; | |
int i = 0, j = 0; | |
/* input section*/ | |
printf("Input width:"); | |
scanf("%d", &width); | |
/* outer loop(y-axis) */ | |
while(i < width) { | |
/* inner loop(x-axis) */ | |
while(j < width) { | |
if(i != 0 && i != width -1) { | |
/* if y-axis is not on edge, | |
* check the y-axis | |
* */ | |
if(j != 0 && j != width - 1) { | |
/* | |
* if x-axis is not on edge, either | |
* fill with blank. | |
* */ | |
printf(" "); | |
} else { | |
/* x-axis is on edge, | |
* fill with '*' | |
* */ | |
printf("*"); | |
} | |
} else { | |
/* | |
* y-axis is on edge, | |
* fill with '*' | |
* */ | |
printf("*"); | |
} | |
/* increment x-axis */ | |
++j; | |
} | |
/* next line, print '\n' and reset x-axis */ | |
printf("\n"); | |
j = 0; | |
/* increment y-axis */ | |
++i; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment