Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created October 11, 2014 04:43
Show Gist options
  • Save henrybear327/ce3bed4c809b1c91a21f to your computer and use it in GitHub Desktop.
Save henrybear327/ce3bed4c809b1c91a21f to your computer and use it in GitHub Desktop.
print a diamond using 1 for loop.c
#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