C program to Convert Decimal to Hexadecimal
1 | | /* Write a program to convert a decimal number to its |
2 | | equivalent hexadecimal number. */ |
3 | | |
4 | | #include <stdio.h> |
5 | | main() |
6 | | { |
7 | | unsigned long dec; |
8 | | int a[25],c=0,i; |
9 | | clrscr(); |
10 | | printf("\nENTER A DECIMAL NUMBER: "); |
11 | | scanf("%lu",&dec); |
12 | | printf("\n%lu IN HEXADECIMAL FORMAT: ",dec); |
13 | | while(dec>0) |
14 | | { |
15 | | a[c]=dec%16; |
16 | | dec=dec/16; |
17 | | c++; |
18 | | } |
19 | | for(i=c-1;i>=0;i--) |
20 | | { |
21 | | if(a[i]>=10) |
22 | | printf("%c",a[i]+55); |
23 | | else |
24 | | printf("%d",a[i]); |
25 | | } |
26 | | getch(); |
27 | | }} |