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.
- How to Use URI Online Judge to Improve Your Coding Skills and Boost Your Career
- 6 Ways to Monetize Your Blog and Earn Money Online
- Banglahour24.com | Bangla News
- BEST FREE GIFT CARD GENERATOR in 2022
- Gravity Forms Free Download GPL
