forked from codinasion/program
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from codinasion/master
Filter program by language
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let num=prompt("enter a number") | ||
for(let i=0;i<num;i++) | ||
{ | ||
console.log(i+1); | ||
} |
19 changes: 19 additions & 0 deletions
19
program/print-reverse-of-a-number-by-recursion/print-reverse-of-a-number-by-recursion.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def reverse_num(num: int, reversed_num: int = 0) -> int: | ||
# Base case: if the number is 0, there are no more digits to reverse | ||
if num == 0: | ||
return reversed_num | ||
|
||
# Get the last digit of the number | ||
last_digit = num % 10 | ||
|
||
# Add the last digit to the beginning of the reversed number | ||
reversed_num = reversed_num * 10 + last_digit | ||
|
||
# Recursively call the function to reverse the remaining digits | ||
return reverse_num(num // 10, reversed_num) | ||
|
||
|
||
# Test the function with a few examples | ||
print(reverse_num(123)) # should print 321 | ||
print(reverse_num(7331)) # should print 1337 | ||
print(reverse_num(87124389372498)) # should print 89427398342178 |