C Program to Print an Equilateral Triangle

Write a program in the c programming language to print an equilateral triangle of the asterisks or by using any other character. Make this program by using for loop statements. Below is the triangle we have to print as a output of the program-


c program triangle

Output as Equilateral Triangle in the C program


Below is the code of the C program to print the above output –

/* C program to print Equilateral Triangle*/
#include<stdio.h>
main()
{
      int i,j,k,n;

      printf("Enter number of rows  of the triangle \n");
      scanf("%d",&n);

      for(i=1;i<=n;i++)
      {
              for(j=1;j<=n-i;j++)
              {
                      printf(" ");
              }
              for(k=1;k<=(2*i)-1;k++)
              {
                      printf("*");
              }
              printf("\n");
      }
      getch();
}

Ouput – Output will be exact as shown in the image above

yashan has written 69 articles

8 thoughts on “C Program to Print an Equilateral Triangle

  1. rj says:

    WITH THE HELP OF TWO LOOPS..YOU BETTER DO THIS WAY
    #include
    void main()
    {
    int i,j;
    for(i=1;i<=4;i++)
    {
    for(j=1;j=(5-i))
    {
    printf(“*”);
    }
    else
    {
    printf(” “);
    }
    }
    printf(“\n”);
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>