Question: use C for two functions: print integer(int n, int radix, char* prefix) with return type : void Print the number n to the console (stdout)

use C for two functions:

print integer(int n, int radix, char* prefix) with return type: void

  • Print the number n to the console (stdout) in the specified number base (radix), with the prefix immediately before the first digit. radix may be any integer between 2 and 36 (inclusive). n may be any int. For values of radix above 10, use lowercase letters to represent the digits following 9. print_integer() should not print a newline ('n' or 'r'). Examples:

    • print integer(768336, 10, "") should print 768336 because the number seven-hundred sixty-eight thousand three-hundred thirty-six would be written as 768336 in base 10 (decimal).
    • print integer(-768336, 10, "") should print -768336.
    • print integer(-768336, 10, "$") should print -$768336. Notice that the prefix ("$") comes after the "-" and before the first digit.
    • print integer(768336, 16, "") should print bb950 because the number seven-hundred sixty-eight thousand three-hundred thirty-six would be written as bb950 in base 16 (hexadecimal).
    • print integer(768336, 16, "0x") should print 0xbb950. The 0x prefix is added only because it is passed as an argument to print_integer().
    • print integer(-768336, 16, "0x") should print -0xbb950.
    • print integer(-768336, 2, "0b") should print -0b10111011100101010000.
    • print integer(768, 10, ""); print integer(-336, 10, "") should print "768336".

******Use fputc and stdout instead of printf

******Can't use arrays to store strings!!!!!!!!!!!!!!

** Please don't copy and paste the answer that was answered already

int main() { print_integer(768336, 10, ""); fputc(' ', stdout); print_integer(-768336, 10, ""); fputc(' ', stdout); print_integer(-768336, 10, "$"); fputc(' ', stdout); print_integer(768336, 16, ""); fputc(' ', stdout); print_integer(768336, 16, "0x"); fputc(' ', stdout); print_integer(-768336, 16, "0x"); fputc(' ', stdout); print_integer(-768336, 2, "0b"); fputc(' ', stdout); print_integer(768, 10, ""); print_integer(-336, 10, "");

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!