迭代——将小于9位的数字字符串转化成整型

#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[10];
    int i,x;
    gets(s);

    x=i=0;
    while(s[i])
    {
        x*=10;
        x+=s[i]-'0';
        ++i;
    }

    printf("%d",x);

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq2071114140/article/details/80343819