Skip to content

Instantly share code, notes, and snippets.

@HelixSpiral
Created January 6, 2012 20:06
Show Gist options
  • Save HelixSpiral/1572165 to your computer and use it in GitHub Desktop.
Save HelixSpiral/1572165 to your computer and use it in GitHub Desktop.
Creates a command-line triangle
/* Creates a triangle */
#include <stdio.h>
int main()
{
/* vars */
int lines, stars, x, y;
printf("How many lines do you wish the triangle to be?: ");
scanf("%d", &lines);
/* Loops for every line, increasing stars by 2 each time */
for(y = 1, stars = 1; y <= lines; ++y, stars += 2)
{
for(x = 0; x <= lines-y; ++x)
printf(" ");
for(x = 1; x <= stars; ++x)
printf("*");
printf("\r\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment