0

Hi, I have this program that outputs a triangle when given the size.
Right now the triangle outputs like this

5
*
**
***
****
*****

Does anyone know how I would make it look like this?

5
1
12
123
1234
12345

Thanks in advanced for looking at my post.

#include<iostream>
using namespace std;
   

int main(){ 
     int num, row;
     cin>>num;
     for(row=0;row<num;row++)
     {
        for (int a=0; a<=row;a++)
        {
            cout<<"*";
            }
            for (int b=num;b>row+1;b--)
            cout<<" ";
            cout<<endl;
            }
            cin.ignore();
            cin.ignore();
            return 0;
            }

Edited by bookmark: n/a

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by bookmark
0

Thanks. Would I have to change the whole code if I want to output it this way as well?

5
5
45
345
2345
12345
0

Not really,

for(row=num;row>0;row--)
for (int a=row-1; a<num;a++)

These will be your outer and inner loops.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.