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 داده شده است. هدف پیدا کردن عدد فیبوناچی قبل از این عدد است. مثال زیر برای درک بهتر مطلب، قابل توجه است.

Input: N = 8
Output: 5
۵ is the previous fibonacci number before 8.


Input: N = 5
Output: 3

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

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

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

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

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

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

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

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

// C# implementation of the approach 
using System; 
  
class GFG 
{ 
      
// Function to return the previous 
// fibonacci number 
static int previousFibonacci(int n) 
{ 
    double a = n / ((1 + Math.Sqrt(5)) / 2.0); 
    return (int)Math.Round(a); 
} 
  
// Driver code 
public static void Main() 
{ 
    int n = 8; 
    Console.Write(previousFibonacci(n)); 
} 
} 
  
// This code is contributed by Akanksha_Rai 

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

۵

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

منبع [+]

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

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