Skip to content

Commit 0337441

Browse files
author
Thejus-Paul
committed
Added Solution
Added Solution for Problem 20
1 parent c787a22 commit 0337441

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Project Euler/Problem 20/sol1.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Finding the factorial.
2+
def factorial(n):
3+
fact = 1
4+
for i in range(1,n+1):
5+
fact *= i
6+
return fact
7+
8+
# Spliting the digits and adding it.
9+
def split_and_add(number):
10+
sum_of_digits = 0
11+
while(number>0):
12+
last_digit = number % 10
13+
sum_of_digits += last_digit
14+
number = int(number/10) # Removing the last_digit from the given number.
15+
return sum_of_digits
16+
17+
# Taking the user input.
18+
number = int(input("Enter the Number: "))
19+
20+
# Assigning the factorial from the factorial function.
21+
factorial = factorial(number)
22+
23+
# Spliting and adding the factorial into answer.
24+
answer = split_and_add(factorial)
25+
26+
# Printing the answer.
27+
print(answer)

Project Euler/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ PROBLEMS:
5252

5353
16. 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
5454
What is the sum of the digits of the number 2^1000?
55+
20. n! means n × (n − 1) × ... × 3 × 2 × 1
56+
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
57+
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
58+
Find the sum of the digits in the number 100!

0 commit comments

Comments
 (0)