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.
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.
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";
}
}