|
|
17Oct/110
Draw a “stdio” BL Right-Angled Triangle C Source Code
Hello again, i've posted about drawing a square shape before. Now we're move a step ahead, drawing a simple right-angled triangle. I give this post BL code which means "Bottom-Left" because we're gonna draw right-angled triangle with the '90' placed at bottom left of the triangle.
* ** *** ****
This post will show two ways to draw that with a same concepts or logic. The basic logic is the number of '*' character in each row is same as the row number.
#include "stdio.h"
#include "conio.h"
int main()
{
int size;
printf("Triangle side size: ");
scanf("%d", &size);
//First method using conditional filtering
for (int i=0;i<size;i++)
{
for (int j=0;j<size;j++)
{
if (j<=i) printf("*");
}
printf("\n");
}
printf("\n");
//Second method using logical looping
for (int i=0;i<size;i++)
{
for (int j=0;j<i+1;j++)
{
printf("*");
}
printf("\n");
}
getch();
return 0;
}
Related posts:




