Hi,
I can deliver you a well commented code, like the solution of Q3, below :)
I look forward to hearing from you. Adrian.
/**
* Write an application that finds the first entry in the fibonacci series
* that is greater than 600 .
* Fibonacci series: 1,1,2,3,5,8,13,21,34,55.....
* Divide that number into its digits (600 would be 6 , 0 , 0) and calculate
* the sum of the factorials of each digit ( 600 would be 6! + 0! + 0!)
*/
public class Program
{
public static int factorial (int N)
{
if (N == 0 || N == 1) return 1; // 0! = 1! = 1
return (N * factorial(N - 1)); // N!=N*(N-1)!
}; // factorial
/* Fibonacci series: 1,1,2,3,5,8,13,21,34,55..... */
public static int fibonacci(int n1, int n2)
{
return (n1 + n2);
} // fibonacci
public static void main(String[] args)
{
//
// the first entry in the fibonacci series that is greater than 600
//
int n1 = 1, n2 = 1;
int N=0;
while (N < 600)
{
/* Fibonacci series: 1,1,2,3,5,8,13,21,34,55..... */
N = n1 + n2;
n1 = n2;
n2 = N;
}; // while
// divide N into its digits (600 would be 6 , 0 , 0)
int d1, d2, d3;
d1 = N / 100; // left-most digit
d2 = (N-d1*100)/10; // middle digit
d3 = N - (d1 * 100 + d2 * 10); // right-most digit
// sum of the factorials of each digit ( 600 would be 6! + 0! + 0!)
int sum;
sum = factorial(d1) + factorial(d2) + factorial(d3);
} // main
} // class Program