Decimal to Hexadecimal conversion in C by R4R Team

Decimal number:
Consists of 10 elements
range : 0 to 9

Hexadecimal number :
Consists of 16 elements
range : 0 to 9 then 'A' to 'F'

Decimal to Hexadecimal conversion:

Example-
Decimal number is 10
Hexadecimal number is A

Decimal number is 15
Hexadecimal number is E

Decimal number is 41
Hexadecimal number is 92


program-

#include< stdio.h>
int main() {
int n,num=0;
printf("Enter decimal number\n");
scanf("%d",&n);
while(n)
{
num=num*10+n%16;
n=n/16;
}
printf("It's Hexadecimal is %d",num);
}


output-

Enter decimal number
41
It's Hexadecimal is 92

-In this program, we take an input of decimal number and find its Hexadecimal equivalent.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!