K&R C Exercise 1-21: entab — Replace Spaces with Tabs

Exercise 1-21. Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing. Use the same tab stops as for detab. When either a tab or a single blank would suffice to reach a tab stop, which should be given preference? Approach entab is …

K&R C Exercise 1-20: detab — Replace Tabs with Spaces

Exercise 1-20. Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be a variable or a symbolic parameter? Approach The key insight is that a tab does not …

C Program to generate Graph using grphics.h

C Program to Generate the graph sheet using the grphics.h library. To use graphics.h, we have to install the drivers in to the the system by using the initgraph() function. Here  we derive the graph of input sizes verses time taken for input sizes. x axis represents inputs(0,10000,20000,—-), y axis rep time(0,0.05,0.1,0.15—). Read more about …

C Program To Implement Interpolation Search

Interpolation search is an algorithm used for searching a given value in an ordered indexed array. Interpolation search is sometimes called as extrapolation search. For uni formally distributed data items Interpolation search is the best method. for example: library books directory. Read more about C Programming Language. /************************************************************ You can use all the programs on …

K&R C Exercise 1-16: Print True Length of Long Input Lines

Exercise 1-16. Revise the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text. The K&R longest-line program (Section 1.9) stores each input line in a fixed buffer of MAXLINE characters. That design silently truncates any line longer than …

K&R C Exercise 1-14: Histogram of Character Frequencies

Exercise 1-14. Write a program to print a histogram of the frequencies of different characters in its input. Approach The key insight here is one of the most elegant idioms in C: a character read from getchar() is already an integer — its ASCII value. That value falls in the range 0–127, so it can …