| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++. |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do I write a recursive function in C++ to display a triangle of * like this using a parameter size (e.g. 4 in the following example):
* ** *** **** I am able to write a recursive function to display an inverted triangle like this: **** *** ** * The code for the inverted triangle function is: Code:
void inverted(int a)
{
if (a==1)
{
cout<<"*"<<endl;
}
else
{
for (int i=0; i<a; i++)
{
cout<<"*";
}
cout<<endl;
inverted(a-1);
}
}
Please, provide some insight into the problem. I need it to work urgently but I am not able to figure out a solution. |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|