# C Program to Convert Decimal Number to Hexadecimal Number

• Write a C program to convert decimal number to hexadecimal number system.
• How to convert decimal number to hexadecimal number.

#### Required Knowledge

Decimal number system is a base 10 number system using digits 0 and 9 whereas Hexadecimal number system is base 16 number system and using digits from 0 to 9 and A to F. Given an decimal number as input from user convert it to hexadecimal number.

##### For Example
1234 in Decimal is equivalent to 4D2 in Hexadecimal number system.

## C program to convert a decimal number to hexadecimal number

```#include <stdio.h>
#include <string.h>

#define BASE_16 16

int main() {
char hexDigits[] = "0123456789ABCDEF";

long decimalNumber;
int index, remaindar;

/*
* Take a Decimal Number as input form user
*/
printf("Enter a Decimal Number\n");
scanf("%ld", &decimalNumber);

index = 0;

/* Convert Decimal Number to Hexadecimal Numbers */
while(decimalNumber != 0) {
remaindar = decimalNumber % BASE_16;
decimalNumber /= BASE_16;
index++;
}

return 0;
}
```
Output
```Enter a Decimal Number
1234
```Enter a Decimal Number