Learn about Triangle Pattern Program in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Triangle Pattern Program in C
If you want to print the triangle pattern like below in C then follow the below code giving number of rows you want.
* * * * * * * * * *
Program:
#include<stdio.h>
int main()
{
int n, r, c;
printf("Enter number of rows: ");
scanf("%d",&n);
for(r=1;r<=n;r++)
{
for(c=1;c<=2*n;c++)
if(c>(2*n-r)) printf("* ");
else printf(" ");
printf("\n");
}
return 0;
}
Output:
Enter number of rows: 5 * * * * * * * * * * * * * * *
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Pattern Program in C for Inverted Full Pyramid
Pattern Program 20 in C