Warning: include(): open_basedir restriction in effect. File(/home/matlabsite/public_html/wp-content/plugins/wp-super-cache/wp-cache-base.php) is not within the allowed path(s): (/home/h321874/:/tmp:/var/tmp:/opt/alt/php81/usr/share/pear/:/dev/urandom:/usr/local/lib/php/:/usr/local/php81/lib/php/) in /home/h321874/domains/matlabsite.com/public_html/wp-content/plugins/wp-super-cache/wp-cache.php on line 95

Warning: include(/home/matlabsite/public_html/wp-content/plugins/wp-super-cache/wp-cache-base.php): failed to open stream: Operation not permitted in /home/h321874/domains/matlabsite.com/public_html/wp-content/plugins/wp-super-cache/wp-cache.php on line 95

Warning: include(): open_basedir restriction in effect. File(/home/matlabsite/public_html/wp-content/plugins/wp-super-cache/wp-cache-base.php) is not within the allowed path(s): (/home/h321874/:/tmp:/var/tmp:/opt/alt/php81/usr/share/pear/:/dev/urandom:/usr/local/lib/php/:/usr/local/php81/lib/php/) in /home/h321874/domains/matlabsite.com/public_html/wp-content/plugins/wp-super-cache/wp-cache.php on line 95

Warning: include(/home/matlabsite/public_html/wp-content/plugins/wp-super-cache/wp-cache-base.php): failed to open stream: Operation not permitted in /home/h321874/domains/matlabsite.com/public_html/wp-content/plugins/wp-super-cache/wp-cache.php on line 95

Warning: include(): Failed opening '/home/matlabsite/public_html/wp-content/plugins/wp-super-cache/wp-cache-base.php' for inclusion (include_path='.:/opt/alt/php72/usr/share/pear') in /home/h321874/domains/matlabsite.com/public_html/wp-content/plugins/wp-super-cache/wp-cache.php on line 95

Warning: include_once(): open_basedir restriction in effect. File(/home/matlabsite/public_html/wp-content/plugins/wp-super-cache/ossdl-cdn.php) is not within the allowed path(s): (/home/h321874/:/tmp:/var/tmp:/opt/alt/php81/usr/share/pear/:/dev/urandom:/usr/local/lib/php/:/usr/local/php81/lib/php/) in /home/h321874/domains/matlabsite.com/public_html/wp-content/plugins/wp-super-cache/wp-cache.php on line 122

Warning: include_once(/home/matlabsite/public_html/wp-content/plugins/wp-super-cache/ossdl-cdn.php): failed to open stream: Operation not permitted in /home/h321874/domains/matlabsite.com/public_html/wp-content/plugins/wp-super-cache/wp-cache.php on line 122

Warning: include_once(): Failed opening '/home/matlabsite/public_html/wp-content/plugins/wp-super-cache/ossdl-cdn.php' for inclusion (include_path='.:/opt/alt/php72/usr/share/pear') in /home/h321874/domains/matlabsite.com/public_html/wp-content/plugins/wp-super-cache/wp-cache.php on line 122
برنامه محاسبه عدد فیبوناچی بعد از یک عدد — راهنمای کاربردی | مرجع متلب و هوش مصنوعی.

برنامه محاسبه عدد فیبوناچی بعد از یک عدد — راهنمای کاربردی

عدد فیبوناچی N داده شده است؛ هدف پیدا کردن عدد فیبوناچی بعد از N است. مثال‌های زیر برای درک بهتر این مطلب، ارائه شده‌اند.

Input: N = 5
Output: 8
۸ is the next fibonacci number after 5

 
Input: N = 3
Output: 5

نسبت دو عدد همجوار در سری فیبوناچی به سرعت به ((۱ + sqrt(5)) / 2) می‌رسد. بنابراین، اگر N در ((۱ + sqrt(5)) / 2) ضرب و گرد شود، عدد حاصل شده در واقع عدد فیبوناچی بعدی است. در ادامه، پیاده‌سازی رویکرد بالا ارائه شده است.

برنامه محاسبه عدد فیبوناچی بعد از یک عدد در ++C

// C++ implementation of the approach 
#include<bits/stdc++.h> 
using namespace std; 
  
// Function to return the next 
// fibonacci number 
int nextFibonacci(int n) 
{ 
    double a = n * (1 + sqrt(5)) / 2.0; 
    return round(a); 
} 
  
// Driver code 
int main() 
{ 
    int n = 5; 
    cout << nextFibonacci(n); 
} 
  
// This code is contributed by mohit kumar 29 

برنامه محاسبه عدد فیبوناچی بعد از یک عدد در جاوا

// Java implementation of the approach  
class GFG 
{ 
      
    // Function to return the next 
    // fibonacci number 
    static long nextFibonacci(int n) 
    { 
        double a = n * (1 + Math.sqrt(5)) / 2.0; 
        return Math.round(a); 
    } 
      
    // Driver code 
    public static void main (String[] args) 
    { 
        int n = 5; 
        System.out.println(nextFibonacci(n)); 
    } 
} 
  
// This code is contributed by AnkitRai01 

برنامه محاسبه عدد فیبوناچی بعد از یک عدد در پایتون

# Python3 implementation of the approach 
from math import *
  
# Function to return the next  
# fibonacci number 
def nextFibonacci(n): 
    a = n*(1 + sqrt(5))/2.0
    return round(a) 
  
# Driver code 
n = 5
print(nextFibonacci(n))

برنامه محاسبه عدد فیبوناچی بعد از یک عدد در #C

// C# implementation of the approach 
using System; 
  
class GFG  
{ 
      
    // Function to return the next 
    // fibonacci number 
    static long nextFibonacci(int n) 
    { 
        double a = n * (1 + Math.Sqrt(5)) / 2.0; 
        return (long)Math.Round(a); 
    } 
      
    // Driver code 
    public static void Main(String[] args) 
    { 
        int n = 5; 
        Console.WriteLine(nextFibonacci(n)); 
    } 
} 
  
// This code is contributed by 29AjayKumar

خروجی قطعه کد بالا به صورت زیر است.

۸

اگر نوشته بالا برای شما مفید بوده است، آموزش‌های زیر نیز به شما پیشنهاد می‌شوند:

منبع [+]

پاسخی بگذارید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *