Displaying Diagonal Lines

The trying to write a program that asks for the number of lines the
user wants to output then the display should scroll down that many
lines with line number starting where col=row. I want it to look like this
(Disregard the "-," I couldn't figure out how to display it without them)
ex: input value: 5
----5
---4
--3
-2
1

However, the code I have written gives an output that looks like this:
1
-2
--3
---4
----5

What would I have to change in my code to produce the first diagonal line? Thanks for your help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 //System Libraries
#include <iostream>
using namespace std;

//Global Constants

//Function Prototypes

//Execution Starts Here
int main(int argc, char** argv) {

    //Declare Variables
    int n;

    //Input number of lines
    cout<<"Enter how many lines would you like to output?\n";
    cin>>n;

    //Output lines and spaces to create diagonal
    for(int lines=1; lines<=n; lines++){
        for(int space=2; space<=lines; space++){
            cout<<" ";
        }
        cout<<lines;
        cout<<"\n";
    }
    
    return 0;
}
Last edited on
Change line 16 and 17 to something like
for(i=n;i>=1;i--)
Last edited on
Topic archived. No new replies allowed.