Recursive Implementation of atoi ( ) | Recursive C program to compute atoi ( ) ; Recursive function to compute atoi ( ) ; Base case ( Only one digit ) ; If more than 1 digits , recur for ( n - 1 ) , multiplu result with 10 and add last digit ; Driver Program
#include <stdio.h> NEW_LINE #include <string.h> NEW_LINE int myAtoiRecursive ( char * str , int n ) { if ( n == 1 ) return * str - '0' ; return ( 10 * myAtoiRecursive ( str , n - 1 ) + str [ n - 1 ] - '0' ) ; } int main ( void ) { char str [ ] = "112" ; int n = strlen ( str ) ; printf ( " % d " , myAtoiRecursive ( str , n ) ) ; return 0 ; }