Вопрос задан 25.02.2019 в 17:23. Предмет Информатика. Спрашивает Мемех София.

Дан ряд Фибоначчи. Найти n-элемент решения.

0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Гущина Алина.

# include <stdio.h>
int phi(int x){
int i,k=0;
if(x>1)k+=phi(x-1)+phi(x-2);
if(x<2)k=x;
return k;}    
int main (void){
int x;
scanf("%d",&x);
printf("%d",phi(x));
return 0;}

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Finding the n-th element of the Fibonacci sequence

To find the n-th element of the Fibonacci sequence, you can use a recursive function or an iterative approach. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones. The sequence starts with 0 and 1, and the subsequent numbers are obtained by adding the two previous numbers.

Here is an example of a recursive function to find the n-th element of the Fibonacci sequence:

```python def fibo(n): if n == 1 or n == 2: return 1 else: return fibo(n - 1) + fibo(n - 2) ```

In this function, if n is equal to 1 or 2, it returns 1. Otherwise, it recursively calls itself with n-1 and n-2 as arguments and returns the sum of the two previous numbers.

To find the n-th element, you can simply call the `fibo` function with the desired value of n. For example, to find the 30th element of the Fibonacci sequence, you would call `fibo(30)`.

The result of `fibo(30)` would be the 30th element of the Fibonacci sequence.

Please note that calculating large Fibonacci numbers can be computationally expensive, especially using the recursive approach. For larger values of n, it is recommended to use an iterative approach or memoization to improve performance.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос