179k views
2 votes
Write program in C to draw a hollow isosceles triangle of height h. Input h from keyboard.

Eg: Input h=4

* * * * * * *

User JhTuppeny
by
5.5k points

1 Answer

4 votes

Answer:

// here is code in C.

#include <stdio.h>

int main()

{

// variable to store height of triangle

int n ;

printf("enter the height of triangle:");

// read the height

scanf("%d",&n);

// variables

int a, b, c = 0;

for (a = 1; a <= n; a++)

{

// Print spaces of the triangle

for (b = a; b < n; b++) {

printf(" ");

}

// Print all * of the triangle

while (c != (2 * a - 1))

if (c == 0

c = 0;

printf("\\");

}

// print last row of the triangle

for (a = 0; a < 2 * n - 1; a++) {

printf("*");

}

return 0;

}

Step-by-step explanation:

Two sides of an isosceles triangle are equal in the length. Read the height of isosceles triangle and assign it to variable "n".Then first print all the spaces of the triangle with the help of two nested for loop.Then print the all * of triangle except the last row of triangle.Then print the last row of triangle With

Output:

enter the height of triangle:4

*

* *

* *

* *

*******

User Xiaofei
by
5.2k points