Skip to content

Instantly share code, notes, and snippets.

@ampulhetadosaber
Created June 29, 2019 04:39
Show Gist options
  • Save ampulhetadosaber/33a359dab10f405dbb405f60e595371e to your computer and use it in GitHub Desktop.
Save ampulhetadosaber/33a359dab10f405dbb405f60e595371e to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
void solve(int numero){ // Modo Recursivo
cout << numero << "\n";
if(numero==1)return; // Chamado de caso base, interrompe a recursão de se chamar infinitamente, causando "Tempo Limite Excedido"
solve(numero-1); // Função chamando a si mesma, gerando uma recursão.
}
int main(){
int n;
cin >> n;
solve(n);
for(int i=n; i>=1; i--){ // Modo Iterativo
cout << i << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment