Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
joegeorge022 authored Dec 3, 2024
1 parent 093d896 commit 8d795e5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
24 changes: 24 additions & 0 deletions factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Name:Joe George
Title: Factorial of a number (With & Without Recursion)
Date: 3 December 2024
"""

# 1. WITHOUT RECURSION
def factorial(n):
result = 1
for i in range(1,n+1):
result *= i
return result

print(factorial(4))


# 2. WITH RECURSION
def recursion_factorial(n):
if n == 1:
return 1
else:
return n*factorial(n-1)

print(recursion_factorial(4))
15 changes: 15 additions & 0 deletions greatest common divisor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'''
Name:Joe George
Title: Greatest Common Divisor.
Date: 3 December 2024
'''

# Greatest Common Divisor
def gcd(a,b):
if a % b==0:
return b
else:
return gcd(b,a%b)

print(gcd(12,16))

14 changes: 14 additions & 0 deletions recursive addition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Name:Joe George
Title: Addition using recursion
Date: 3 December 2024
"""

def add_nums(a, b):
if b == 0:
return a
else:
return add_nums(a+1, b-1)

print(add_nums(10, 10))

13 changes: 13 additions & 0 deletions recursive multiply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Name:Joe George
Title: Multiplication using recursion
Date: 3 December 2024
"""

def multiply(a, b):
if b == 1:
return a
else:
return a + multiply(a, b-1)

print(multiply(10, 10))

0 comments on commit 8d795e5

Please sign in to comment.