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 …

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 …

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 …

K&R C Exercise 1-12: Print Input One Word Per Line

Exercise 1-12. Write a program that prints its input one word per line. Approach A word is any contiguous run of non-whitespace characters; spaces, tabs, and newlines are all separators. The challenge is not reading words — it is knowing when to emit the newline that separates them in the output. The solution borrows the …

K&R C Exercise 1-10: Make Tabs and Backspaces Visible

Exercise 1-10. Write a program to copy its input to its output, replacing each tab by t, each backspace by b, and each backslash by \. This makes tabs and backspaces visible. Approach The exercise is deceptively simple to state but teaches something subtle about C: the difference between a character’s value in the program …