Fibonacci
Write a program that receives 2 users and calculates the Fibonacci series (between those two) and prints in the output
Write a program that receives 2 users and calculates the Fibonacci series (between those two) and prints in the output
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
def fibonacci_in_range(start, end):
"""این تابع سری فیبوناچی را در بازه مشخص شده محاسبه و چاپ میکند."""
a, b = 0, 1
fibonacci_numbers = []
while a <= end:
if a >= start:
fibonacci_numbers.append(a)
a, b = b, a + b # Updating Fibonacci values
return fibonacci_numbers
def main():
# Receive two numbers from the user
start = int(input("لطفاً عدد شروع را وارد کنید: "))
end = int(input("لطفاً عدد پایان را وارد کنید: "))
# Calculate and print the fibonacci series in the specified interval
fibonacci_numbers = fibonacci_in_range(start, end)
print(f"سری فیبوناچی در بازه [{start}, {end}]: {fibonacci_numbers}")
# Implementation of the program
main()
num1 = int(input('number1 : '))
num2 = int(input('number 2 :'))
counter = num1
while counter < num2 - 1 :
counter += 1
print(counter)
h1=int(input("Please,enter number 1:\n"))
h2=int(input("Please,enter number 2:\n"))
l=[0,1]
a=0
b=1
while True:
c=a+b
if c<=h2:
l.append(c)
a=b
b=c
continue
else:
break
for i in l:
if h1<=i<=h2:
print(i)
def fibonacci_in_range(start, end):
a, b = 0, 1
while a <= end:
if a >= start:
print(a, end=' ')
a, b = b, a + b
start = int(input("عدد اول را وارد کنید: "))
end = int(input("عدد دوم را وارد کنید: "))
fibonacci_in_range(start, end)
def fibonacci_in_range(start, end):
fib_sequence = []
a, b = 0, 1 # Starting with the first two fibonacci numbers
# Fibonacci series production until the number is larger than the END
while a <= end:
if a >= start: # If the number is in the interval, add to the list
fib_sequence.append(a)
a, b = b, a + b # Updating values A and B
return fib_sequence
def main():
try:
# Receive two numbers from the user
start = int(input("عدد شروع را وارد کنید: "))
end = int(input("عدد پایان را وارد کنید: "))
# Calculate the fibonacci series in the interval
fib_numbers = fibonacci_in_range(start, end)
# View results
print(f"سری فیبوناچی بین {start} و {end}: {fib_numbers}")
except ValueError:
print("لطفاً فقط اعداد صحیح وارد کنید.")
# Implementation of the program
main()
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> # To understand the capacity of variables:
#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;
}
Submitting answers is currently unavailable.
You must be logged in to access this section.
Login/Sign up If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.