Copying Sample C Programs

To copy one of the examples , say, harmonic1.c from the labdemos directory, then compile and run it, proceed as follows:
   % cp /u/cl/lib/labdemos/c/harmonic1.c .
   % gcc -o har harmonic1.c
   % har

Note the period in the cp command. It stands for your current directory. Note also that we have to give the full path to harmonic1.c, namely /u/cl/lib/labdemos/c/harmonic1.c

This program computes partial sums of the harmonic series, e.g.,

   harmonic(4) = 1 + 1/2 + 1/3 + 1/4

Once you have copied the file to your directory can view the source code with one of the commands

   % more harmonic1.c
   % emacs harmonic1.c