Sample C Programs

The directory /u/cl/lib/labdemos/c has sample programs that you can copy and study. To list these programs, type
   ls /u/cl/lib/labdemos/c

Index of programs

The programs are listed in an order of study, from the least to the most sophisticated.

Everyone's first program Write a message to the screen using printf.
Find the sum harmonic(n) = 1 + 1/2 + 1/3 + ... + 1/n where n = 20. Introduces the for loop.
A refinement of the previous program: it asks the user to define n. Introduces scanf.
Another refinement: the user can compute harmonic(n) many times. Introduces the do-while loop.