Complicated problem [closed]

-7

How to do in C ++ a program that prints the user's number as follows:

5 4 3 2 1
5 4 3 2
5 4 3
5 4
5

This is very complicated for me.

    
asked by anonymous 27.10.2017 / 13:59

1 answer

2

Try this code:

#include <iostream>

using namespace std;

void imprimeRecursivo(int numero, int final) {
  if(final <= numero) {
    for (int i = numero; i >= final; i--) {
        cout << i;
    }
    cout << "\n";
    imprimeRecursivo(numero, final + 1);
  }
}

int main()
{ 
  imprimeRecursivo(5, 1);
}

And if it is not recursive:

void imprimeComLoop(int numero, int final) {
    for ( int p = final; p <= numero; p++) {
        for (int i = numero; i >= p; i--) {
            cout << i;
        }
        cout << "\n";
    }
}
    
27.10.2017 / 14:35