Monday, 2 June 2014

0

C Program 11: To Print a Right Angled Triangle

  • Monday, 2 June 2014
  • IndianBooktuber
  • Share
  • Aim:  To print this pattern
    *
    **
    ***
    ****
    *****
    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
         int i, j, n;
         printf("Click on number of lines you want to print: ");
         scanf("%d", &n);
         for (i=1; i<=n; i++)
          {
                   for (j=1; j<=i; j++)
                   {
                       printf("*");
                   }
                   printf("\n");
          }
    getch();
    }

    Theory:  The pattern is the simplest pattern. One thing you should remember while creating patterns is that the first for loop is always for the number of lines you want to cover with your pattern. Here we have asked the user to enter how many lines he wants to print the pattern in.
    Then we have used the condition for (i=1; i<=n; i++) to print the stars according to the way we want. The choice is condition depends upon your logical capabilities and may differ.
    This is the output:

    0 Responses to “C Program 11: To Print a Right Angled Triangle”

    Post a Comment

    Subscribe