diff --git a/Fibonacci.py b/Fibonacci.py new file mode 100644 index 0000000..cab9c30 --- /dev/null +++ b/Fibonacci.py @@ -0,0 +1,10 @@ +def fib(n): #Nth FIBONACCI number generator function + if n==1 or n==2: #1st and 2nd terms are 1 + return 1 + else: + return fib(n-1)+fib(n-2) #all other terms will be calculated recursively + +n=int(input("Enter how many fibonacci terms you want to print: ")) #taking user input +print("The fibonacci series upto ",n,"th term is:-") #giving desired output +for i in range(1,n+1): + print(fib(i),end=" ") #looping till n terms and printing the terms as space seperated integers \ No newline at end of file diff --git a/GCD.py b/GCD.py new file mode 100644 index 0000000..b648ab6 --- /dev/null +++ b/GCD.py @@ -0,0 +1,8 @@ +def gcd(a,b): #gcd function + while (b): #while b not equal to 0 + a,b=b,a%b + return abs(a) + +a,b=map(int,input("Enter 2 numbers: ").split()) #take user input of 2 numbers +c=gcd(a,b) #call the gcd function +print("The gcd of ",a," and ",b," is ",c) #output the result \ No newline at end of file