Home

A program to print the format - right aligned column numbers triangle

C Programming Language 045

The following code shows how to write a program to print the following format.

   1
  21
 321
4321

Program

#include <stdio.h>

void main()
{
    int i, j, k, space = 3;
    {
        for (i = 1; i <= 4; i++)
        {
            for (k = 1; k <= space; k++)
            {
                printf(" ");
            }
            space--;
            for (j = i; j >= 1; j--)
            {
                printf("%d", j);
            }
            printf("\n");
        }
    }

    printf("\n");
}

Result

   1
  21
 321
4321


Last Updated on

Next Post: Rules vs Guidelines →

Comments