The atoi() function takes a string (which represents an integer) as an argument and returns its value.
We have discussed iterative implementation of atoi(). How to compute recursively?
We strongly recommend you to minimize your browser and try this yourself first
The idea is to separate the last digit, recursively compute the result for remaining n-1 digits, multiply the result with 10 and add the obtained value to the last digit.
Below is the implementation of the idea.
This article is contributed by Narendra Kangralkar. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Write your own atoi()
- Recursive Functions
- Recursive Insertion Sort
- Recursive function to check if a string is palindrome
- Recursive function to do substring search
- String slicing in Python to check if a string can become empty by recursive deletion
- Program to count vowels in a string (Iterative and Recursive)
- Recursive Programs to find Minimum and Maximum elements of array
- Recursive program to print formula for GCD of n integers
- Recursive solution to count substrings with same first and last characters
- Recursive Tower of Hanoi using 4 pegs / rods
- Recursive function to delete k-th node from linked list
- Recursive insertion and traversal linked list
- Count consonants in a string (Iterative and recursive methods)
- First uppercase letter in a string (Iterative and Recursive)
- Recursive approach for alternating split of Linked List
- Recursive program for prime number
- Function to copy string (Iterative and Recursive)
- Recursive Practice Problems with Solutions
- Check if linked list is sorted (Iterative and Recursive)