# c program to convert decimal number to hexadecimal number

list of c programs below: c program to convert decimal number to hexadecimal number using functions, c program to convert decimal number to hexadecimal number without functions

Hexadecimal number is a number represented using 16 symbols which are 0 -9 numbers and A – F alphabets. Procedure to convert decimal number to hexadecimal number is: Divide the decimal  number with 16 at each step and take remainders

Here for remainders 0 – 9 numbers are used and then to represent 10 to 15 numbers we use alphabets A, B, C, D, E, F .

eg  To convert decimal number 10 to hexadecimal

16  | 10
| 0 – A

Now combine all remainders serially from down to up  i.e  A . This is hexadecimal number of  10 (decimal )

Program Logic: Enter decimal number n, divide n by 16 ( since hexadecimal ) and save remainder in array and quotient in n repeat until n is greater than zero

## Write a C program to convert decimal number to hexadecimal number using functions

Write a C Program to convert decimal number to hexadecimal using functions

#include <stdio.h>
void main()
{
int num;
printf(“\n OUTPUT: c program for converting decimal number to hexadecimal number \n Enter decimal number: “);
scanf(“%d”,&num);
printf(“\n Hexadecimal number of binary number %d is: num”);
}

{
while (n>0)
{
int i=0,b;
b[i]=n%16;
n=n/16;
i++;
}
while(i>0)
{
if (b[i]<10)
{
printf(b[i]);
}
else
{
switch(b[i])
{
case 10:
printf(“A”);
break;
case 11:
printf(“B”);
break;
case 12:
printf(“C”);
break;
case 13:
printf(“D”);
break;
case 14:
printf(“E”);
break;
case 15:
printf(“F”);
break;
}
//close switch
}
//close else
i–;
}
//close while
}
//close main
}
//close function

## Write a C program to convert decimal number to hexadecimal number without functions

Write a c program to convert decimal number to hexadecimal number without functions

#include <stdio.h>
void main()
{
int i=0,n,b;
printf(“\n OUTPUT: c program for converting decimal number to hexadecimal number \n Enter decimal number: “);
scanf(“%d”,&n);
while (n>0)
{
b[i]=n%16;
n=n/16;
i++;
}
while(i>0)
{
if (b[i]<10)
{
printf(b[i]);
}
else
{
switch(b[i])
{
case 10:
printf(“A”);
break;
case 11:
printf(“B”);
break;
case 12:
printf(“C”);
break;
case 13:
printf(“D”);
break;
case 14:
printf(“E”);
break;
case 15:
printf(“F”);
break;
}
//close switch
}
//close else
i–;
}
// close while
}
//close main

OUTPUT:

OUTPUT: c program for converting decimal number to hexadecimal number
Enter decimal number:25
{"ft_lang_label":"__label__en","ft_lang_prob":0.5436388,"math_prob":0.9976717,"size":3314,"snap":"2019-51-2020-05","text_gpt3_token_len":881,"char_repetition_ratio":0.2471299,"word_repetition_ratio":0.3385214,"special_character_ratio":0.2736874,"punctuation_ratio":0.14308426,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9982354,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-27T03:37:24Z\",\"WARC-Record-ID\":\"<urn:uuid:8e3582bd-c579-43c4-a590-7c230cc19a07>\",\"Content-Length\":\"26563\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a5b09b90-501c-4163-9eef-dce71444366b>\",\"WARC-Concurrent-To\":\"<urn:uuid:36fe47b5-e410-47df-90ec-6ce0aa3d6e60>\",\"WARC-IP-Address\":\"166.62.10.189\",\"WARC-Target-URI\":\"http://www.programmingsimplysolved.com/c-programs/c-program-convert-decimal-number-hexadecimal-number/\",\"WARC-Payload-Digest\":\"sha1:FWVC6KBSPPVTSXJPGPPJNCCBOCIYKFJ4\",\"WARC-Block-Digest\":\"sha1:ASELH6GSMSMGH6JZV6B5NXTG3XOBJWBL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579251694176.67_warc_CC-MAIN-20200127020458-20200127050458-00367.warc.gz\"}"}