DevJourney · code I wrote while learning

README.md

1.6 KB

nth fibonacci number is odd or even and then sum of digits

Single File Programming Question

Problem Statement

Paul, a mathematics teacher, is working on a project to help his students understand the Fibonacci sequence better. He wants to create a simple program that takes an integer 'n' as input and calculates the nth Fibonacci number.Additionally, he wants to implement a method to check if the calculated Fibonacci number is even or odd and then calculate the sum of its digits.

Help Paul to achieve this by implementing the class FibonacciCalculator.This class will contain methods for:

Calculating the nth Fibonacci number. Checking if the Fibonacci number is even or odd. Calculating the sum of digits of the Fibonacci number.

Input:

format :

The input is a single integer 'n' representing the position of the Fibonacci number to be calculated.

Output:

format :

The first line of output displays "Fibonacci number at position n: " followed by an integer representing the nth Fibonacci number calculated.

The second line displays whether the Fibonacci number is "Even" or "Odd" (without quotes) and its digit sum in the format

<Odd/Even, Digit Sum: >

Refer to the sample output for the formatting specifications.

Code constraints : The given test cases fall under the following constraints:

0 ≤ n ≤ 100

The calculated Fibonacci number will fit within the range of a 64-bit integer.

Sample test cases :

Input 1:

7
Output 1 :
Fibonacci number at position 7: 13
Odd, Digit Sum: 4
Input 2 :
3
Output 2 :
Fibonacci number at position 3: 2
Even, Digit Sum: 2