(C语言)输入一行任意字符串,输出字符串中最大的正整数如果字符串中不包含数字,则输出0)
int main(void)
{
char str[100];
gets(str);
int i = 0, max = 0, n = 0;
while (str[i])
{
if (str[i] >= '0' && str[i] <= '9')
{
n = n * 10 + str[i] - '0';
}
if (str[i] < '0' || str[i] > '9' || str[i + 1] == '\0')
{
if (max < n)
max = n;
n = 0;
}
i++;
}
printf("%d", max);
return 0;
}