URI Online Solve | 1957 Converting to Hexadecimal- Solution

Uri Online Solve

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

URI Online https://www.urionlinejudge.com.br/judge/en/problems/view/1957Judge | 1957

Converting to Hexadecimal

By M.C. Pinto, UNILA BR  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 SamplesOutput Samples
10A
15F
1610
Output Sample

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.

Uri Online Solve
Uri Online Solve 1957

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Do You Want To Contact With me?

drop us a line and keep in touch