Goal
To explore various algorithms for solving problems using the built-in simple types in C++
simple.java
") from your teacher.
factors (Integer num)
that will print all the factors of a given positive
integer. For example, factors (30) should produce the following formatted output (note that a period terminates the list):GCD(Integer a, Integer b)
that returns the greatest common divisor of its two positive
integer parameters.
prime(Integer num)
that determines whether a given
integer greater than one is a prime number. Use this header:Boolean prime(Integer num)
Double power (Double base, Integer exponent)
that raises a given number (floating point or
integer) to a given (positive, negative, or zero) integer power. Do NOT use pow (x)
or log (x)
in your solution. Note that if the base is zero, the exponent must be positive.
findDigit (Integer num, Integer n)
that returns the nth digit from the right of a given
integer where n is a positive integer. For example,findDigit (30568,2)
will return 6findDigit(234,5)
will return 0findDigit(-4532,3)
will return 5downDigits(Integer num)
that will list the digits of a positive
integer in one column. For Example:downDigits (560)
will produce this output:The digits of 560 are:
5
6
0
Bonus!
Write a function countDigits (Double num)
that returns the number of digits to the left of the decimal point of a valid floating point number. Note that countDigits (0.74) returns 1.