0
#include<iostream>
using namespace std;
int main()
{
    int x,inpt,ctrl;
    x=1;
    ctrl=1;
    cout<<"Enter a number: ";
    cin>>inpt;
    while(ctrl<=inpt)
    {
               while(x<=ctrl)
               {
                                cout<<x<<" ";
                                x++;
                                }
                                cout<<"\n";
                                ctrl++;
                                x=1;
                                }
    system("pause");
}

can u please help me to invert this triangle?

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by prvnkmr449
0

Set your x and ctrl to whatever you input for inpt.

Then you can run through ( ctrl > 0 )

and output x like

[B]while X is larger than zero then
    print X
    subtract one from X
endwhile[/B]

Decrement your ctrl counter and set X equal to ctrl and you're done

Edited by chococrack: n/a

0

Hi ,
Example >>5
output
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

If you want this type of output
then initialize x and ctrl by inpt variable

while(ctrl>=1)
{
while(x>=1)
{
cout<<x<<" ";
x--;
}
cout<<"\n";
ctrl--;
x=ctrl;
}

Best Of Luck

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.