integer assume

advertisement
Complete both exercises depending on your number in the group list. Numbers 11-20 should subtract 10
from their position in the list to pick their exercises. Please e-mail you solutions to mrybokas@gama.vtu.lt
no later than 12 January, 2005. The solutions will be worth three points of your total grade.
1. Write a program that reads three nonzero double values and determines and prints if they could represent
the sides of a triangle.
2. Write a program that reads three nonzero integers and determines if they could be the sides of a right
triangle.
3. Write a program that sums a sequence of integers. Assume that the first integer read specifies the number
of values remaining to be entered. Your program should read only one value per input statement. A typical
input sequence might be
5 100 200 300 400 500, where the 5 indicates that the subsequent 5 values are to be summed.
4. Write a program that calculates and prints the average of several integers. Assume the last value read is
the sentinel 9999. A typical input sequence might be
10 8 11 7 9 9999 indicating that the average of all values preceding 9999 is to be calculated.
5. Write a programs that finds the smallest of several integers. Assume that the first value read specifies the
number of values remaining and that the first number is not one of the integers to compare.
6. Write a program that calculates and prints the product of the odd integers from 1 to 15.
7. Write a program that evaluates the factorials of the integers from 1 to 10 and print the results in tabular
format.
8. Write a program that reads five numbers (each between 1 and 30). For each number read, your program
should print a line containing that number of adjacent asterisks. For example, if your program reads the
number seven, it should print *******.
9. Write a program that prints a table of the binary equivalents of the decimal number in the range 1 through
256.
10. Calculate the value of pi from the infinite series:
pi = 4–4/3+4/5–4/7+4/9–4/11+… Print a table that shows the value of pi approximately by 1 term of the
series, by two terms, etc. How many terms of this series do you have to use before you first get 3.14? 3.141?
3.1415? 3.14159?
1. Use a single-subscripted array to solve the following problem. Read in 20 numbers, each of which is
between 10 and 100, inclusive. As each number is read, print it only ir it is not duplicate of a number
already provided. Provide for the “worst case” in which all 20 numbers are different. Use the smallest
possible array to solve this problem.
2. Write function distance that calculates the distance between two points (x1, y1) and (x2, y2). All numbers
and return types should be of type double.
3. The greatest common divisor (GCD) of two integers is the largest integer that evenly divides each of the
numbers. Write a function gcd that returns the greatest common divisor of two integers.
4. Write a function that takes an integer value and returns the number with its digits reversed. For example,
given the number 7631, the function should return 1367.
5. Write a function that determines whether a number is prime.
6. Write a function that takes the time as three integer arguments (for hours, minutes and seconds), and
returns the number of seconds since the last time the clock “struck 12.”
7. Write a function that returns the smallest of three double-recision, floating point numbers.
8. Write a function integerPower(base, exponent) that returns the value of baseexponent. Assume that exponent
is a positive, non-zero integer and that the base is an integer. Do not use any math library functions.
9. Write a function multiple that determines for a pair of integers whether the second integer is a multiple of
the first.
10. Define a function hypotenuse that calculates the length of the hypotenuse of a right triangle when the
other two sides are given.
Download