فیبوناچی
برنامه ای بنویسید که 2 عدد از کاربر دریافت کند و سری فیبوناچی را در آن بازه (بین آن دو عدد) محاسبه و در خروجی چاپ کند
👨💻 3 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد
برنامه ای بنویسید که 2 عدد از کاربر دریافت کند و سری فیبوناچی را در آن بازه (بین آن دو عدد) محاسبه و در خروجی چاپ کند
min_num = int(input('minimum number: '))
max_num = int(input('maximum number: '))
a = 0
b = 1
while 1:
a,b = b,a+b
if a >= min_num:
print(a)
if a > max_num:
break
#include <iostream>
#include <cfloat> // برای فهمیدن ظرفیت متغیر ها :
#include <cctype>
#include <vector>
using namespace std ;
int main() {
int Fn_2=0 ;
int Fn_1=1 ;
int Fn ;
cout << Fn_2 <<","<< Fn_1 <<"," ;
while ( 1 ) {
Fn = Fn_1 + Fn_2 ;
cout << Fn <<"," ;
Fn_2 = Fn_1 ;
Fn_1 = Fn ;
}
return 0;
}
t = int(input("ta: "))
# اعداد فیبوناچی
def fib(n):
a, b = 0, 1
while a<n:
print(a, end='-')
a, b = b, a+b
print()
fib(t)
function fibo(start, end) {
const fib = [];
let a = 0;
let b = 1;
while (a <= end) {
if (a >= start) fib.push(a);
const next = a + b;
a = b;
b = next;
}
return fib;
}
const start = parseInt(prompt("enter number"));
const end = parseInt(prompt("enter number"));
const resulte = fibo(start, end);
console.log(`start: ${start} , end: ${end} : ${resulte}`);
def fibonacci(n):
"""
This function calculates the nth number of the Fibonacci sequence.
Arguments:
n: The index of the number we want to calculate the Fibonacci value of.
return:
nThe most important number in the Fibonacci sequence
"""
if n <= 0:
return "Please enter a positive number."
elif n == 1:
return 0
elif n == 2:
return 1
else:
fib_prev, fib_next = 0, 1
for _ in range(2, n):
fib_prev, fib_next = fib_next, fib_prev + fib_next
return fib_next
# Example of using the function:
number = int(input("Please enter the desired index in the Fibonacci sequence: "))
result = fibonacci(number)
print("Fibonacci number in index", number, "is equal to:", result)
produce fibonacci and append it to a list and search if haveing that value then print it if our last fibonacci got bigger that our first number that represent start of interval then add a number to it until it reach to second number.
x=int(input("enter number: "))
y=int(input("enter number: "))
f1=0
f2=1
g=[]
x+=1
while x<y:
fc=f1+f2
g.append(fc)
if x in g:
print(x)
f1=f2
f2=fc
if fc>x:
x+=1
i=int(input('pleas input number for start:'))
o=int(input('pleas input number for end:'))
fibonachi=[]
a,b=0,1
while a<=o:
if i<=a<=o:
fibonachi.append(a)
a,b=b,a+b
print(f"input {i}and{o}: {fibonachi}")
a = int(input("عدد اول: "))
b = int(input("عدد دوم: "))
x = 0
y = 1
while x <= b:
if x >= a:
print(x)
x, y = y, x + y
جوابت را با Markdown بنویس و ثبت کن
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نامتوضیح کوتاهی بنویسید تا تیم بررسی کند.