C Program to Print Triangle of Stars

Write a program in the C programming language to print the triangle of stars. Make a right angled triangle. You can also print any other character of your choice.  Below is the pattern of the triangle-


*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *



This C program is made by using the nested for loops to print asterisks . Below is the code of the program-

/* C program to print triangle of stars or of any other character */

#include<stdio.h>
void main()
{
     int n,i;

     for(n=1;n<=20;n++)
     {
             for(i=1;i<=n;i++)
             {
                     printf("*");
             }
             printf("\n");
     }
     getch();
}

Output – Output will be same as the triangle made above

yashan has written 69 articles

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>