From 3bdcf0ef251c0fb3ff4cd225772c449dcda4101a Mon Sep 17 00:00:00 2001 From: DEVIL-NEEL Date: Sat, 22 Oct 2022 00:53:43 +0530 Subject: [PATCH 1/2] GCD FUNCTION --- GCD.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 GCD.py 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 From 1f74ff4203f2054fd32ec940ce6b88c8d5086344 Mon Sep 17 00:00:00 2001 From: DEVIL-NEEL Date: Sat, 22 Oct 2022 01:02:57 +0530 Subject: [PATCH 2/2] FIBONACCI SERIES FUNCTION --- Fibonacci.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Fibonacci.py 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