Skip to content

Instantly share code, notes, and snippets.

@ardrabczyk
Last active January 23, 2019 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ardrabczyk/631379a8e25d59c01f7922dfdd26be92 to your computer and use it in GitHub Desktop.
Save ardrabczyk/631379a8e25d59c01f7922dfdd26be92 to your computer and use it in GitHub Desktop.
Character triangle
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int chars_in_line = 7;
char current_letter = 65; /* ASCII A */
int current_chars_in_line = chars_in_line;
for(int i = 0; i < chars_in_line; i++)
{
printf("%*s", chars_in_line - current_chars_in_line, "");
for(int i = 0; i < current_chars_in_line; i++)
{
printf("%c", current_letter++);
if (current_letter == 91) /* if we got to Z start from A again */
current_letter = 65;
}
printf("\n");
current_chars_in_line--;
}
return EXIT_SUCCESS;
}
@ardrabczyk
Copy link
Author

Output:

$ ./triangle
ABCDEFG
 HIJKLM
  NOPQR
   STUV
    WXY
     ZA
      B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment