Mathematics 216: Assignment 1

Problems

  1. Learn to type in and compile some simple demonstration programs: hello.c, hello2.c, and harmonic.c. The first just prints a greeting on the screen. The second uses a loop to print this greeting many times. A loop is a way of commanding a computer to do something over and over again.
  2. The previous two programs were just a warm-up. Now we will use the idea of loop to do something interesting. Consider the infinite series
           1 + 1/2 + 1/3 + ... + 1/n + ...
    
    The n-th partial sum is what you get by adding up the first n terms. Type in and run the program sum.c to compute the n-th partial sum for n = 10, n = 100, n = 1000, and n = 10,000. Graph the partial sums and say what you can about their growth as n increases.

    Consider next the question of whether the partial sums approach a limit L. This happens if the n-th partial sum s(n) gets closer and closer to L as n gets larger and larger. In this case we say that the series converges. In the contrary case we say that it diverges . One way a series can diverge is by getting larger and larger, with out bound. In other words, for any number A that you pick, I can find an integer N such that s(n) > A if n > N. In this case we say the series diverges to infinity.

    The harmonic series diverges to infinity. This fact was already known in the fourteenth century to Nicolas Oresme , a thirteenth century Scholastic philosopher. Given what was known at the time, his argument must have been quite elementary. Can you find it?


Remarks

Work that you turn in should be in the form of a brief, clearly written report. Writing it by hand is just fine, but you can use a computer if you wish. Do include a print-out of the program text. You may wish to annotate it by hand. Include program output where relevant. Strive for a readable report. It should clearly state the problem to be solved and the conclusions reached.

Tips

Here is how to type in your first program. Bold text is what you type. Normal text is computer output. Italic text is comment.
 Type in the program using the cat command: 

  % cat >hello.c
  #include <stdio.h>  
   main()
   {
     printf( "Hello world!\n" );
   }
  <control-D>

Verify that the program is there: 

  % ls hello.c 
  hello.c

Check that the program text is OK using cat
a different way:

  % cat hello.c
    #include <stdio.h>  
     main()
     {
        printf( "Hello world!\n" );
     }


Compile the program: 

  % gcc -o hello hello.c

Now the program has been translated from
C to machine language.  The machine language
version is stored in the file hello.
To run this program we type its name:

  % hello
  Hello world!

To write more elaborate programs you should learn to use a text editor, e.g., emacs . The best way to do this is to type the command emacs , then type C-h t (control-h followed by ordinary t). This will put you in the online emacs tutorial.


Back to syllabus
Back to Department of Mathematics, University of Utah
Last modified: Feb 21, 1995
Copyright © 1995 Department of Mathematics, University of Utah