Skip to content

Instantly share code, notes, and snippets.

@dwikipedia
Created July 8, 2017 09:20
Show Gist options
  • Save dwikipedia/262e1d249a0ffdd23b70d302290a21a7 to your computer and use it in GitHub Desktop.
Save dwikipedia/262e1d249a0ffdd23b70d302290a21a7 to your computer and use it in GitHub Desktop.
Kinds of Triangles using for
/*
#
##
###
####
#####
*/
for (int x = 1; x <= 5; x++)
{
for (int y = 1; y <= x; y++)
{
Console.Write("#");
}
Console.WriteLine(" ");
}
/*
#
##
###
####
#####
*/
int a = 5;
for (int x = 1; x <= a; x++)
{
for (int y = 1; y <= a - x; y++)
{
Console.Write(" ");
}
for (int z = 1; z <= x; z++)
{
Console.Write("#");
}
Console.WriteLine(" ");
}
/*
#####
####
###
##
#
*/
int b;
for (int x = 1; x <= a; x++)
{
for (b = 1; b <= a - x; b++) { }
for (int z = 1; z <= b; z++)
{
Console.Write("#");
}
Console.WriteLine(" ");
}
/*
#
# #
# # #
# # # #
# # # # #
# # # # # #
# # # # # # #
# # # # # # # #
# # # # # # # # #
# # # # # # # # # #
*/
for (int x = 1; x <= 10; x++)
{
for (int y = 1; y < 9-x+2; y++)
{
Console.Write(" ");
}
for (int z = 1; z <= x; z++)
{
Console.Write("#");
Console.Write(" ");
}
Console.WriteLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment