Created
October 11, 2014 04:43
-
-
Save henrybear327/ce3bed4c809b1c91a21f to your computer and use it in GitHub Desktop.
print a diamond using 1 for loop.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> | |
#include <stdlib.h> | |
int main() | |
{ | |
char str1[] = "********************************************"; | |
char str2[] = " "; | |
int space = 1, star, initial_star; | |
scanf("%d", &star); | |
initial_star = star; | |
for(space = 1; star * (-1) <= | |
initial_star; space += 2, star--) | |
{ | |
if(star >= 0) | |
printf("%.*s%.*s%.*s\n", star, str1, space, str2, star, str1); | |
else | |
printf("%.*s%.*s%.*s\n", (-1)*star, str1, space - 2 * 2 * (-1) * star, str2, (-1)*star, str1); | |
} | |
return 0 ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment