ferseg

Decimal a Binario

Sep 12th, 2014
28,461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. /*  Autor: Joel Cesar Fernandez Segura
  2.     Fecha: 28/08/2014
  3.     Tema: Recursividad
  4.     Ejercicio 3: convertir numero decimal a binario
  5. */
  6.  
  7. #include<iostream>
  8. #include<cstdlib>
  9. using namespace std;
  10.  
  11. int binario(int n){
  12.     if(n>1)      binario(n/2);
  13.     cout<<n%2;
  14. }
  15. int main( void ){
  16.     system("color 0a");
  17.     int nro;
  18.     cout<<"\n\t\t[     RECURSIVIDAD     ]\n";
  19.     cout<<"\t\t------------------------\n\n";
  20.     cout<<" EJERCICIO 2: Convertir a binario un numero decimal "<<endl<<endl;
  21.  
  22.     do{
  23.             cout<<" INGRESE NUMERO: ";
  24.             cin>>nro;
  25.             if(nro<0) cout<<"\nINGRESE UN NUMERO ENTERO Y POSITIVO... \n";
  26.     }while(nro<0);
  27.     cout<<endl;
  28.     cout<<"\n Numero:"<<nro<<endl;
  29.     cout<<"\n Binario:";
  30.     binario(nro);
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment