Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main()
- {
- int dec_num , r;
- string hexdec_num="";
- char hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- cout << "Input a decimal number : ";
- cin>> dec_num;
- if(dec_num>=0&&dec_num<=15)
- {
- while(dec_num>0)
- {
- r = dec_num % 16;
- hexdec_num = hex[r] + hexdec_num;
- dec_num = dec_num/16;
- }
- cout<<"The hexadecimal number is : "<<hexdec_num<<"\n";
- }
- else
- {
- cout<<dec_num<<" is an invalid input";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment