Hi!

I have to write program, who print Triangle made with numbers from 1 to 9,like this:

1
21
321
4321
54321
654321
7654321
87654321
987654321

I wrote code:

#include <iostream.h>
#include <stdlib.h>

int main()
{
 int first, last;

 cout << endl;

 for (first = 1 ; first <= 9 ; first++)
 {
    cout << " ";
    for (last = 1 ; last <= first; last++)
    {
       cout <<last;
    }
 cout<< endl;
 }

 cout << endl << endl << endl;
 system("PAUSE");
 return 0;
}

which put on the screen Triangle in form:
1
12
123
1234
12345
123456
1234567
12345678
123456789

I think, that I need to use if statment to invert numbers, but i dont know how. Any ideas?

Simple replace

for (last = 1 ; last <= first; last++)

with

for (last = first ; last >=1; --last)

replace the above line and every thing is fine.

YES!!!
IT works!
Thank you Laiq Ahmed!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.