|
Take a look at the following program to count triangles, which should help you:
#include<iostream.h>
void main()
{
const int position = 30; // Specify the position of the triangle vertex
const int lines = 6; // Specify the number of lines to be printed
// Front lines-1 line
for( int i=0; i<lines-1; ++i)
{
for(int stars=0; stars<=80; ++stars)
{
if ((stars==position-i) || (stars==position+i))
cout <<'*';
else
cout << '';
}
cout << endl;
}
// the last line
for(int stars=0; stars<=80; ++stars)
{
if ((stars>=position-i)&&(stars<=position+i))
cout <<'*';
else
cout << '';
}
} |
|