Write a program to accept the number of rows and print Left, Center and Right-Aligned triangles.

/* Write a program to accept the number of rows and print the following outputs

Left-aligned Triangle

*

* *

* * *

* * * *

Center-aligned Triangle

   *

  * *

 * * *

* * * *

Right-aligned Triangle

      *

    * *

  * * *

* * * *

using dependent nested loop.*/

#include <stdio.h>

void main()

{

    int rows, i,j;

    printf("Enter the number of rows : ");

    scanf("%d",&rows);

    printf("Left-aligned Triangle\n");

    for(i=1;i<=rows;i++)

    {

        for(j=1;j<=i;j++)

        {

            printf("* ");

        }

        printf("\n");

    }

    printf("Center-aligned Triangle\n");

    for(i=1;i<=rows;i++)

    {

        printf("%*s",rows-i,"");

        for(j=1;j<=i;j++)

        {

            printf("* ");

        }

        printf("\n");

    }

    printf("Right-aligned Triangle\n");

    for(i=1;i<=rows;i++)

    {

        printf("%*s",(rows-i)*2,"");

        for(j=1;j<=i;j++)

        {

            printf("* ");

        }

        printf("\n");

    }

    getch();

}

Comments

Popular posts from this blog

Write a program to accept numerator and denominator and find the remainder without using modulus (%) operator using do..while loop.