Category «While loop»

The index of a Fibonacci number

The index of a Fibonacci number. The Fibonacci sequence is defined as follows: ϕ0=0, ϕ1=1, ϕn=ϕn−1+ϕn−2. Given an integer a, determine its index among the Fibonacci numbers. Print the number n such that ϕn=a. If a is not a Fibonacci number, print -1. Test Case Input (a) Expected Output 1 0 0 2 1 1 3 10 -1 …

Fibonacci numbers

Fibonacci numbers. The Fibonacci sequence is defined as follows: ϕ0=0, ϕ1=1, ϕn=ϕn−1+ϕn−2. Given a non-negative integer n, print the nth Fibonacci number ϕn. Solve this problem using a for loop. Test Case Input (n) Expected Output 1 0 0 2 1 1 3 10 55  

The second maximum

The second maximum. The sequence consists of distinct positive integers and ends with the number 0. Determine the value of the second largest element in this sequence. It is guaranteed that the sequence has at least two elements. Test Case Input (Sequence) Expected Output 1 1 2 3 0 2 2 10 5 8 0 …

The index of the maximum of a sequence

The index of the maximum of a sequence. A sequence consists of integer numbers and ends with the number 0. Determine the index of the largest element in the sequence. If the largest element is not unique, print the index of the first occurrence. Test Case Input (Sequence) Expected Output 1 1 2 3 0 …

The maximum of the sequence

The maximum of the sequence. A sequence consists of integer numbers and ends with the number 0. Determine the largest element in the sequence. Test Case Input (Sequence) Expected Output 1 1 2 3 0 3 2 4 0 1 2 4 3 7 3 5 0 7