//starter code to finish: // Task 4 stringbuilder task_4_ans = task_4_check(x); stringbuilder task_4 = get_bin_2
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
//starter code to finish: // Task 4 stringbuilder task_4_ans = task_4_check(x); stringbuilder task_4 = get_bin_2
// Task 4
stringbuilder task_4_ans =
task_4_check(x);
stringbuilder task_4 = get_bin_2(x);
printf("\n");
if (!sb_is_equal(task_4, task_4_ans))
printf("FAILED");
else
printf("PASSED");
printf(": GET BINARY 2 (Task 4)\n");
printf("Expected: \"%s\"\n",
*task_4_ans.cars);
printf(" Got: \"%s\"\n",
*task_4.cars);
delete_sb(task_4_ans);
delete_sb(task_4);
printf("\n");
printf("Input a number (1234 to exit): ");
scanf("%d", &x);
Task 4 Get Binary 2: Implement the get_bin_2 function as directed in the comment above the function. If the directions are unclear, run the code, and look at the expected answer for a few inputs. For your solution, you should refer to your solution for Task 2 to get the general idea for Task 4, and you should use largest_po2_le in your solution (think about why this might be useful in terms of the binary representation). Make sure you build the string for 0 and negative numbers correctly. The same restrictions apply from Task 2.