整理思路:
#include <stdio.h>
int len(const char *s)
{
int len = ;
while (s[len])
{
len++;
}
return len;
}
int myPower10(int len)
{ if (len == )
return ;
if (len == )
return ; int power = ;
for (int i = ; i < len; i++)
power *= ;
return power;
}
int myCToInt(char c)
{
c = c - '';
return c;
} int myAtoi(const char *s)
{
int i, volue = ,lens = len(s);
for (i = ; i < lens; i++)
{
volue += myCToInt(s[i]) * myPower10(lens - i - );
}
return volue;
} int main()
{
char a[] = "";
int volue = myAtoi(a);
printf("%d", volue);
return ;
}
运行:
3321
换一种思路呢: