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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Write your own atoi()
- Recursive Functions
- Modular exponentiation (Recursive)
- Recursive Bubble Sort
- Recursive Insertion Sort
- Recursive program to generate power set
- Recursive program for prime number
- Recursive function to do substring search
- Recursive program to print all subsets with given sum
- Bitwise recursive addition of two integers
- Recursive program to find the Sum of the series 1 - 1/2 + 1/3 - 1/4 ... 1/N
- Recursive Program for Binary to Decimal
- Recursive Practice Problems with Solutions
- First uppercase letter in a string (Iterative and Recursive)
- Function to copy string (Iterative and Recursive)
- Program to reverse a string (Iterative and Recursive)
- Recursive Tower of Hanoi using 4 pegs / rods
- Recursive program to find all Indices of a Number
- Recursive solution to count substrings with same first and last characters
- Recursive program to replace all occurrences of pi with 3.14 in a given string