Thread
Print

C++ code problem...please help?

i got a wrong output... it supposed to be like this:
1
12
123

what i get is:
1
21
321

where did i go wrong? please help me... here is my code:

// practice.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;
int triangle(int n);

int _tmain(int argc, _TCHAR* argv[])
{
int n;

        cout<<"enter number : ";
        cin>>n;
        cout<<triangle(n)<<endl;
       

}


int triangle(int n)
{
int
         if (n < 0)
        return 0;        
    else
    {
                triangle(n - 1);  
        
        while(n > 0)
        {
            cout<<n;
            n--;
        }
        cout<<endl;
       
    }
}



thanks guys...

TOP

Thread