document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*  Autor: Joel Cesar Fernandez Segura
  2.     Fecha: 28/08/2014
  3.     Tema: Recursividad
  4.     Ejercicio 2: Suma de los n primeros numeros naturales
  5. */
  6.  
  7. #include<iostream>
  8. #include<cstdlib>
  9. using namespace std;
  10.  
  11. int suma(int nro){
  12.     if(nro==0) return 0;
  13.     if(nro==1) return 1;
  14.     else return nro+suma(nro-1);
  15. }
  16. int main( void ){
  17.     system("color 0a");
  18.     int nro;
  19.     cout<<"\\n\\t\\t[     RECURSIVIDAD     ]\\n";
  20.     cout<<"\\t\\t------------------------\\n\\n";
  21.     cout<<" EJERCICIO 2: Suma de N primeros Numeros Naturales"<<endl<<endl;
  22.     cout<<" INGRESE CANTIDAD DE TERMINOS:";
  23.     cin>>nro;
  24.  
  25.     cout<<endl<<endl;
  26.     for(int i=1;i<nro+1;i++){   //Mostramos la sucesion de terminos
  27.         cout<<i;
  28.         if(i<nro) cout<<" + ";
  29.     }
  30.     cout<<"\\n\\nLa Suma es: "<<suma(nro)<<endl<<endl;
  31.  
  32.     return 0;
  33. }
');