-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
Retos/Reto #14 - OCTAL Y HEXADECIMAL [Fácil]/c++/dylanb55.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |