Question: //In this assignment, we will write code to convert a decimal number to a hexadecimal number #include #include #include //convert the decimal integer d to

//In this assignment, we will write code to convert a decimal number to a hexadecimal number

#include #include #include

//convert the decimal integer d to hexadecimal, the result is stored in hex[] void dec_hex(int d, char hex[]) { char digits[] ={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

int k = 0; //Fill in your code below //It should not be hard to obtain the last digit of the hex number by dividing with 16. Think what you will get if you keep dividing a number by 16. When should you stop? //If you are getting the digits in the reverse order, what should you do in the end?

//Make sure the last character is a zero so that we can print the string correctly hex[k] = '\0'; }

// Do not change the code below int main() { int d; char hex[80]; printf("Enter a positive integer : "); scanf("%d", &d); dec_hex(d, hex); printf("%s ", hex); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!