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
- 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 insertion and traversal linked list
- 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)
- Bitwise recursive addition of two integers
- Program to reverse a string (Iterative and Recursive)
- Recursive program to generate power set
- Level order traversal with direction change after every two levels | Recursive Approach