CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2
  • Faltering Windows support
  • Internet Explorer 8 Click Clever Click Safe
  • Release Candidate 2 for ASP.NET MVC 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    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
    Prev Previous Post   Next Post Next
      #1    
    Old November 20th, 2009, 03:53 AM
    codeyy codeyy is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 5
    codeyy is an unknown quantity at this point (<10)
    Unhappy C++ recursive function (very simple one)... [help needed!]

    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);
    	}
    }
    I am allowed to use a loop (e.g. for loop) to print a row of * but I must use a recursive function to control the number of rows.

    Please, provide some insight into the problem. I need it to work urgently but I am not able to figure out a solution.
    Reply With Quote
     

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 12:11 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.