Skip to content

Commit

Permalink
Merge pull request #6425 from dylanb55/main
Browse files Browse the repository at this point in the history
Reto #14 - C++
  • Loading branch information
Roswell468 authored Mar 24, 2024
2 parents 2bd7e99 + f0838b7 commit 336e7c1
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 336e7c1

Please sign in to comment.