Homework 3

Transcription

Homework 3
ES 112
Labwork & Homework
08/04/2015
Labwork:
1. Write a C function named gcd which receives two integers as input, and calculates and
returns their greatest common divisor as output. Also write a main function which reads two
integers from user, calls the gcd function and prints the output to the screen.
2. Write a C program which calculates the arithmetic and geometric means of the positive
numbers entered by the user. The program should continue reading until the user enters (ctrl
z). Your program should watch for non-positive numbers that may be entered by the user.
3. The value of the number π can be calculated using the following equation:
⎛
⎝
1
3
1
5
1
7
1
9
⎞
⎠
π = 4⎜1 − + − + − L⎟
Knowing π = arccos(−1.0) ; write a C function which finds how many terms of the above
series must be used to exactly calculate the first 6 digits of the number π. Also write a main
function which would call your function.
Homework (Due: 15/04/2015)
1. Problem 1 on page 324 of the text book. (Hint: use the built-in tolower function defined
in char.h file.
2. Problem 17 on page 331 of the text book. (Hint: Review the Case Study on page 298).
Notes: • You must submit your homework as a hard (printed) copy at the specified lecture or lab hour.
• Homework sent using e-mail will be disregarded.
• Late homework submissions will not be accepted.
• Include a screen shot of the program’s output along with your program to your assignment.
WARNING: Cheating and/or copying somebody else’s work will NOT be tolerated and will be officially reported to the Dean's Office.