#include
int main(int argc, char* argv[])
{
printf("\n%d\n", myatoi("1998"));
getch();
return(0);
}
int myatoi(const char *string)
{
int i;
i=0;
while(*string)
{
i=(i<<3) + (i<<1) + (*string - '0');
string++;
//i am using left shift which is equals to multiply by pow(2,n) & shifting is fast then multiplication
// Don't increment i!
}
return(i);
}
Run Herehttps://ideone.com/XUKdL
No comments :
Post a Comment