Skip to content

Commit

Permalink
Merge pull request #1 from codinasion/master
Browse files Browse the repository at this point in the history
Filter program by language
  • Loading branch information
0ME9A committed Dec 18, 2022
2 parents 80877ae + d443bee commit bde9d26
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions program/print-numbers-from-1-to-n/PrintNumbersFrom1ToN.js
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);
}
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

0 comments on commit bde9d26

Please sign in to comment.