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();
}