Skip to content

Commit 40b1703

Browse files
init
1 parent 86cdfac commit 40b1703

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Convert_decimal_to_hexa

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <stdio.h>
2+
void decimal2Hexadecimal(long num);
3+
4+
int main()
5+
{
6+
long decimalnum;
7+
8+
printf("Enter decimal number: ");
9+
scanf("%ld", &decimalnum);
10+
11+
decimal2Hexadecimal(decimalnum);
12+
13+
return 0;
14+
}
15+
16+
/********function for convert decimal number to hexadecimal
17+
* number****************/
18+
void decimal2Hexadecimal(long num)
19+
{
20+
long decimalnum = num;
21+
long quotient, remainder;
22+
int i, j = 0;
23+
char hexadecimalnum[100];
24+
25+
quotient = decimalnum;
26+
27+
while (quotient != 0)
28+
{
29+
remainder = quotient % 16;
30+
if (remainder < 10)
31+
hexadecimalnum[j++] = 48 + remainder;
32+
33+
else
34+
hexadecimalnum[j++] = 55 + remainder;
35+
36+
quotient = quotient / 16;
37+
}
38+
39+
// print the hexadecimal number
40+
41+
for (i = j; i >= 0; i--)
42+
{
43+
printf("%c", hexadecimalnum[i]);
44+
}
45+
46+
printf("\n");
47+
}

0 commit comments

Comments
 (0)