I Made Krisna's Times My Way to Write the Times

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:

  1. Draw a “stdio” Square Shape C Source Code
  2. Hello World MPI C Source Code
  3. Greedy Activity Selector C Source Code
  4. Tower of Hanoi C Source Code
  5. Rail-Fence Cipher C# Source Code
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.