K&R C Exercise 3-5: itob — Integer to Any Base String

Exercise 3-5. 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) should produce in s a hexadecimal string. itob generalises itoa from base 10 to any base 2–36. The only change to the digit-extraction loop is replacing n % 10 with n …

K&R C Exercise 3-4: itoa — Handle INT_MIN in Integer to String

Exercise 3-4. In a two’s complement number representation, our version of itoa does not handle the largest negative number, that is, the value of n equal to −(2wordsize−1). Explain why not. Modify it to print that value correctly, regardless of the machine on which it runs. This exercise has two parts: explain the bug, then …

C Program to get the system information.

C Program to get the system information. We can use the ‘uname’ function to get the system information, which is defined in the “sys/utsname.h” library.Structure is used to hold information returned by the uname function.“uname” function members and their use:sysname returns the name of the operating system in use.release returns the current release level of …

C Program to reverse a Linked List.

Data structures using C,C Program to reverse a Linked List. Linked list is a data structure in which the objects are arranged in a linear order. Linked List contains group of nodes, in which each node contains two fields, one is data field and another one is the reference field which contains the address of …

C Program to implement Integration.

C Program to Implement Numerical Integration (Trapezoidal / Rectangle Rule) Numerical integration approximates a definite integral by summing the areas of thin vertical slices under the curve. The rectangle rule divides the interval [a, b] into N equal strips and sums f(x) * width for each strip. Integration is used in engineering and science to …

K&R C Exercise 3-3: expand — Expand a-z Shorthand into Full Range

Exercise 3-3. Write a function expand(s1,s2) that expands shorthand notations like a-z in the string s1 into the equivalent complete list abc…xyz in s2. Allow for letters or digits on either end of a range, and take care of cases like a-b-c and a-z0-9 and -a. Arrange that a leading or trailing – is taken …