Click on any exercise below to see the source code, program output and explanation of the code. Programs in this section make use of structures. A structure in C is a collection of one or more variables, possibly of different types, grouped together under a single name for convenient handling (K&R, The C Programming Language).
Exercise 4.6. Write a structure declaration for a straight line and a function which, given the coordinates of a point on the line and its gradient, displays the equation of the line.
Equation of a straight-line: y = mx + c
Exercise 4.7. A survey of 10 Hip-Hop / R&B records is made. Each person votes by specifying 3 values (between 1 and 10) representing their choice of first, second and third. The first choice scores 4 points, the second 2 and the third 1 point. Using structures, write a program to read the data, process the votes and display the most popular record. Appropriate validations should be incorporated into the program (A person cannot vote the same record twice).