K&R C Exercise 1-22: Fold Long Lines at Word Boundaries

Exercise 1-22. Write a program to “fold” long lines into two or more shorter lines after the last non-blank character that occurs before the n-th column of input. Make sure your program does something intelligent with very long lines, and if there are no blanks or tabs before the specified column. Line folding is the …

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 implement Linear regression algorithm.

Linear Regression  is the predicting the value of one scalar variable(y) using the explanatory another variable(x). Linear regression  is represented by the equation Y = a + bX, where X is the explanatory variable and Y is the scalar variable. The slope of the line is b, and a is the intercept. For linear list …

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-15: Rewrite Temperature Conversion Using a Function

Exercise 1-15. Rewrite the temperature conversion program of Section 1.2 to use a function. Section 1.2 of K&R embeds the conversion formula directly inside main. It works — but it ties the formula to one spot in the code. This exercise asks you to extract that logic into a separate function called celsius. The payoff …

K&R C Exercise 1-13: Histogram of Word Lengths

Exercise 1-13. Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging. Approach The program breaks into two clear phases: counting word lengths, then rendering the histogram. Counting reuses the IN/OUT state machine …