笔试题(设计函数)
1.设计函数 int atoi(char *s),
笔试题(设计函数)
。int atoi(char *s)
{
char sign;
char sign_val = 1;
int val = 0;
int n = 0;
/* skip spaces */
while (isspace(*s))
++s;
if (*s == '-' || *s == '+')
/* skip '-' and '+' sign */
{
sign = *s;
if (sign == '-')
sign_val = -1;
++s;
}
/* when goes here, it is not space or sign */
while ((*s != '\0') && isdigit(*s))
{
val = 10 * n + (*s - '0');
n = val;
s++;
}
if (*s != '\0')
{
printf("non digit in your input!!\n");
exit(-1);
}
/* non error occured */
return (sign_val * val);
}
2.int i=(j=4,k=8,l=16,m=32); printf("%d", i); 输出是多少?
结果为: 32.
【笔试题(设计函数)】相关文章:
2.笔试题(函数类)
5.360笔试题目
6.360笔试题目