URI Online https://www.urionlinejudge.com.br/judge/en/problems/view/1957Judge | 1957
Converting to Hexadecimal
By M.C. Pinto, UNILA BrazilTimelimit: 1
Data stored in computers are in binary. An economic way of visualizing these numbers is the usage of base 16 (hexadecimal). Your task is to write a program that, given a natural number at base 10, shows its representation in hexadecimal.
Input
The input is a positive integer number V at base 10 (1 ≤ V ≤ 2 x 109).
Output
The output is the same number V at base 16 in a single line (don’t forget the end-of-line character). Use uppercase letters, as shown in the examples.
Input Samples | Output Samples |
10 | A |
15 | F |
16 | 10 |
Solution
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,i=0;
cin>>n;
int arr[100000];
while(n)
{
arr[i]=n%16;
n/=16;
i++;
}
while(i--)
{
if(arr[i]==10)
{
cout<<'A';
}
else if(arr[i]==11)
{
cout<<'B';
} else if(arr[i]==12)
{
cout<<'C';
} else if(arr[i]==13)
{
cout<<'D';
} else if(arr[i]==14)
{
cout<<'E';
} else if(arr[i]==15)
{
cout<<'F';
}
else cout<<arr[i];
}cout<<endl;
return 0;
}
Uri Online Solve 1957
Data stored in computers are in binary. An economic way of visualizing these numbers is the usage of base 16 (hexadecimal). Your task is to write a program that, given a natural number at base 10, shows its representation in hexadecimal.
- Best Laravel App Developer in Mirpur, Dhaka – Nurnobi Shanto
- Best Laravel App Developer in Dhaka – Nurnobi Shanto
- A Podpourri of Learning Options: Pods, Hubs, and Microschools #2
- Code to Create: Showcasing Web Development Projects
- Designing for Impact: A Portfolio of Creative Solutions
