K&R Exercises

Exercise 3-5: Integer to a string in any base

Write the function itob(n,s,b) that converts the integer n into a base b character representation in the string s. In particular, itob(n,s,16) formats s as a hexadecimal integer in s.

Use the digits 0 to 9 and then the lower case letters a to z, so b is from 2 to 36. Write a negative n as a minus sign followed by the digits of its magnitude. Each input line holds n and b, separated by a blank, with n fitting in an int. Print s on a line of its own.

Test Cases

· space→ tab↵ newline

Submissions

No submissions yet