2017-09-29 19:38:15 +03:00
|
|
|
/*****Decimal to Hexadecimal conversion*******************/
|
|
|
|
#include <stdio.h>
|
|
|
|
void decimal2Hexadecimal(long num);
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
long decimalnum;
|
|
|
|
|
|
|
|
printf("Enter decimal number: ");
|
|
|
|
scanf("%ld", &decimalnum);
|
|
|
|
|
|
|
|
decimal2Hexadecimal(decimalnum);
|
|
|
|
|
|
|
|
return 0;
|
2017-09-29 19:38:15 +03:00
|
|
|
}
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
/********function for convert decimal number to hexadecimal
|
|
|
|
* number****************/
|
|
|
|
void decimal2Hexadecimal(long num)
|
|
|
|
{
|
|
|
|
long decimalnum = num;
|
|
|
|
long quotient, remainder;
|
|
|
|
int i, j = 0;
|
|
|
|
char hexadecimalnum[100];
|
2017-09-29 19:38:15 +03:00
|
|
|
|
|
|
|
quotient = decimalnum;
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
while (quotient != 0)
|
|
|
|
{
|
2017-09-29 19:38:15 +03:00
|
|
|
remainder = quotient % 16;
|
2020-05-29 23:23:24 +03:00
|
|
|
if (remainder < 10)
|
2017-09-29 19:38:15 +03:00
|
|
|
hexadecimalnum[j++] = 48 + remainder;
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
else
|
|
|
|
hexadecimalnum[j++] = 55 + remainder;
|
2017-09-29 19:38:15 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
quotient = quotient / 16;
|
|
|
|
}
|
2017-09-29 19:38:15 +03:00
|
|
|
|
|
|
|
// print the hexadecimal number
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
for (i = j; i >= 0; i--)
|
|
|
|
{
|
|
|
|
printf("%c", hexadecimalnum[i]);
|
|
|
|
}
|
2017-09-29 19:38:15 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
printf("\n");
|
2017-09-29 19:38:15 +03:00
|
|
|
}
|