C Programming Language (CS2402): HW4

Instructor: J.-S. R. Jang


Due date: Oct. 14, 1996
  1. (30%) Exercise 4.27 (page 143) of Chapter 4. Note that each Pythagorean triple should be listed in a separate row, and the three sides should be in increasing order. A sample output list is as follows:
    
        Side A    Side B    Side C
             3         4         5
             5        12        13
             6         8        10
             7        24        25
    	 .         .         .
    	 .         .         .
    	 .         .         .
           325       360       485
           340       357       493
    	
    How many number of Pythagorean triples can your program find?
  2. (50%) Exercise 4.26 (page 143) of Chapter 4. You don't need to print out the whole table; just print out the number of terms and corresponding PI values when certain levels are reached. A sample output list is as follows:
    # of terms    PI value
           119  3.149995866593470 ---> 3.14 is reached when 119 terms are added.
          1688  3.141000236580159 ---> 3.141 is reached when 1688 terms are added.
         10794  3.141500009528466 ---> 3.1415 is reached when 10794 terms are added.
        136121  3.141599999994786 ---> 3.14159 is reached when 136121 terms are added.
    	
    Note that this is typical numerical computation; the numbers of terms obtained from your computer may be different from mine due to computer truncation/round-off errors.
If you use any functions defined in "math.h", make sure you use the right option when compiling the program. For instance, if you want to compile a program that uses the function "sqrt", you need to Again, remember that you need to demonstrate these two programs to TA, so make sure you understand every details of your programs.