From 52776a1709c16ec38294ee4069a63e36c8ef2bac Mon Sep 17 00:00:00 2001 From: dylanb55 <161396341+dylanb55@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:56:12 -0300 Subject: [PATCH] Create dylanb55.cpp --- .../c++/dylanb55.cpp" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/c++/dylanb55.cpp" diff --git "a/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/c++/dylanb55.cpp" "b/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/c++/dylanb55.cpp" new file mode 100644 index 0000000000..5eea361ce0 --- /dev/null +++ "b/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/c++/dylanb55.cpp" @@ -0,0 +1,50 @@ +#include +#include +using namespace std; + +void octal(int numero){ + vector octal; + //Algoritmo octal + while(numero > 0){ + octal.push_back(numero % 8); + numero = numero / 8; + } + cout << "El numero en octal es: "; + //Reversa del numero + for(int i = octal.size()-1; i>= 0;i--){ + cout << octal[i]; + } +} + +void hexadecimal(int numero){ + int resto; + vector hexadecimal; + //Algoritmo Hexadecimal + while(numero > 0){ + resto = numero%16; + if(resto < 10){ + resto = resto + 48; + hexadecimal.push_back(resto); + } + else{ + resto = resto + 55; + hexadecimal.push_back(resto); + } + numero = numero/16; + } + cout << "El numero en hexadecimal es: "; + //Recursion + for(int i = hexadecimal.size()-1;i>= 0;i--){ + cout << hexadecimal[i]; + } +} +int main(){ + int numero; + + cout << "Ingrese un numero: " << endl; + cin >> numero; + + octal(numero); + cout << endl; + hexadecimal(numero); +}