Symmetrical Triangle | Pattern | Programming in C

Build your programming skills and logic in ā€œCā€ language.

Question

To input the height of the triangle and draw the above pattern on screen.

Code Solution

#include<stdio.h>
#include<math.h>
#include<conio.h>

main()
{
	int h,r,c;
	clrscr();

	printf("\n Enter the height of the triangle: ");
	scanf("%d",&h);

	for (r=1; r<=h; r++)
	{
		printf("\n");
		for (c=1; c<=40-r; c++)
			printf(" ");
		for (c=r; c>=1; c--)
			printf(" %d",c);
		for (c=2; c<=r; c++)
			printf(" %d",c);
	}
	getch();
}

Leave a Reply

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