hollow triangles

closed account (ENyU7k9E)
i want to generate a hollow triangle but i am not getting any idea about that.

i am a new with programming.
plz give code with explanation b/c i hv not read all the topics yet.
Last edited on
How do you want that triangle to be drawn?
With stars? With a Graphic Library?
Well how would you draw a primitive block A?
-------*
-----*--*
----****
---*-----*
--*-------*
Is this something like what you had in mind?
Last edited on
closed account (ENyU7k9E)
i want triangle is to be drawn with stars by using only iostream.h
closed account (ENyU7k9E)
buffbill it should be like this
---------*
---------**
---------*--*
---------*---*
---------*----*
---------*------*
---------*--------*
---------********
plz give me code for this program by using nested loops and iostream library only
plz give me code
Not many will give you code.
Post what you got so far and we will help you
closed account (ENyU7k9E)
i am too confused about this program that how to write its code.
If you know that you need to use nested loops start from there
LOL i love these types of posts
give me code for this program by using nested loops and iostream library only


i am too confused about this program that how to write its code

welcome to programming....its not easy.
In the absence of anything more useful google pascal`s triangle and observe how the blanks (' ')
are printed on the LHS of the triangle using setw() for the same purpose as our dashes (-). Similarly, spaces will be required inside the triangle.
closed account (ENyU7k9E)
i have tried it by using setw();
but i am not getting the correct way to sort out this problem.
plz help me
i have to give exam on tuesday.
i am too confused about this program that how to write its code.
i have tried it by using setw();
Did you write something or not? Post what you have if you did
closed account (ENyU7k9E)
#include <iostream>
using namespace std;
int main()
{
int z=0;
int i, j;
int spaces;
int g=10;

for (i=1; i<12; i++)
{
for (spaces=g; spaces>0; spaces--)
{
cout << " ";
}
for (j=1; j<z; j++)
{
cout << "*";
}
cout << endl;
z+=2;
g--;
}
return 0;
}

i have written this code but there is a logical error in it.
It's almost OK, you only need to fix a bit this loop:
1
2
3
4
for (j=1; j<z; j++)
{
    cout << "*"; // with this you will draw a filled triangle
}

Hint: you want to draw only the borders so when j gets its first and last values ( 1 and z-1 ) and when i gets its last value ( 12-1 = 11 ) to draw the base. When one of these conditions are met draw a star, otherwise draw a space

and please use [code][/code] tags http://www.cplusplus.com/articles/firedraco1/
Last edited on
Topic archived. No new replies allowed.