- //Decimal to Hex value
- main()
- {
- char hex[16]={"0123456789ABCDEF"};
- int num,i=0,j;
- char result[];
- printf("Enter the Decimal No.\n");
- scanf("%d",&num);
- while(num)
- {
- result[i]=hex[num%16];
- num=num=num/16;
- i++;
- }
- printf("Given num of the hex value is:");
- for(j=i-1;j>=0;j--)
- printf("%c",result[j]);
- getch();
- return 0;
- }
Decimal to Hex
|
Newbie Member
|
|
| 13Jun2012,13:23 | #1 |
|
|
|
Newbie Member
|
|
| 13Jun2012,13:25 | #2 |
|
Quote:
Originally Posted by bmsangati |
|
Ambitious contributor
|
|
| 13Jun2012,22:19 | #3 |
|
I was going to code one for you but I found one online. Source
Code: C
It's not meant to be a complete copy paste method but it is meant to show you what you were doing wrong. You made an array with 16 items but only assigned it one value. Each character needs to be a separate item in the array for this to work. Last edited by pein87; 13Jun2012 at 22:21.. |

