feat: 📝 Update repo
This commit is contained in:
46
Algo/B2/Exercises/Repetitive tutorial.md
Normal file
46
Algo/B2/Exercises/Repetitive tutorial.md
Normal file
@ -0,0 +1,46 @@
|
||||
## Exercise 1.1
|
||||
```python
|
||||
def zorglub(n: int) -> int:
|
||||
j = 1
|
||||
k = 0
|
||||
i = 1
|
||||
while i <= n:
|
||||
j = i * j
|
||||
k = j + k
|
||||
i = i + 1
|
||||
return k
|
||||
```
|
||||
|
||||
The function return the sum of the factorial of n
|
||||
|
||||
## Exercise 1.2
|
||||
```
|
||||
def multiplication(x: int, y: int) -> int:
|
||||
result = 0
|
||||
for i in range(y):
|
||||
result = result + x
|
||||
return result
|
||||
|
||||
def multiplication2(x: int, y: int) -> int:
|
||||
result = 0
|
||||
if x < 0 and y < 0:
|
||||
i = 0
|
||||
x = -x
|
||||
y = -y
|
||||
while i < y:
|
||||
result = result + x
|
||||
i += 1
|
||||
return result
|
||||
elif y < 0:
|
||||
y = -y
|
||||
i = 0
|
||||
while i < y:
|
||||
result = result + x
|
||||
i += 1
|
||||
return -result
|
||||
else:
|
||||
i = 0
|
||||
while i < y:
|
||||
result = result + x
|
||||
i += 1
|
||||
return result
|
Reference in New Issue
Block a user