Question: Complete the program conversion_to_binary.c provided as boileplate code to you. Read the contents of this boilerplate source code file to get a specification of what

Complete the program conversion_to_binary.c provided as boileplate code to you. Read the contents of this boilerplate source code file to get a specification of what this program needs to achieve. Input/ Output examples are given below.

#include  int main(int argc, char **argv) { int n, k, l, r, t, d, i; char str[65]; /* Make the user enter a non-negative integer */ printf("Please enter a non-negative integer: "); scanf("%d", &n); while (n < 0) { printf("Sorry, your input is incorrect. "); printf("Please enter a non-negative integer: "); scanf("%d", &n); } /* Convert the integer to reversed binary: e.g. 6 gets converted to 011 */ if (n == 0) { /* Special case for n = 0 */ str[0] = '0'; str[1] = '\0'; } else { /* Common case */ k = n; /* TODO */ } /* The conversion made the string come out reversed, so reverse the string again. DO NOT USE A COPY OF THE STRING. DO NOT USE ANY LIBRARY FUNCTION (no strlen or other !) */ /* TODO */ /* Display the number and the string */ printf("The decimal number %d is %s in binary. ", n, str); return 0; } 

Input/Output Examples:

Please enter a non-negative integer: 42 The decimal number 42 is 101010 in binary.

Please enter a non-negative integer: 1 The decimal number 1 is 1 in binary.

Please enter a non-negative integer: -1 Sorry, your input is incorrect. Please enter a non-negative integer: 17 The decimal number 17 is 10001 in binary.

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!