File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments