Skip to content

Commit

Permalink
Create dylanb55.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanb55 authored Mar 22, 2024
1 parent 0db934f commit 52776a1
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Retos/Reto #14 - OCTAL Y HEXADECIMAL [Fácil]/c++/dylanb55.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<iostream>
#include<vector>
using namespace std;

void octal(int numero){
vector<int> 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 <char> 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);
}

0 comments on commit 52776a1

Please sign in to comment.