Home > database >  Save the children, to enter a decimal string converted to decimal integer, input data error error. W
Save the children, to enter a decimal string converted to decimal integer, input data error error. W

Time:10-06


# include
# include

Int main (void)
{
Char STR [80].
Int I, n;

I=0;
While ((STR [i++]=getchar ())!='\ n');

If (STR [0]=='+')
{
For (I=1, n=0; STR [I]!='\ 0'; I++)
{
If (STR [I]>='0' && STR [I] <='9')
{
N=n * 10 + STR [I] - '0';
}
The else
{
Printf (" error! \n");
break;
}
}
Printf (" % d \ n ", n);
}

If (STR [0]=='-')
{
For (I=1, n=0; STR [I]!='\ 0'; I++)
{
If (STR [I]>='0' && STR [I] <='9')
{
N=n * 10 + STR [I] - '0';
}
The else
{
Printf (" error! \n");
break;
}
}
Printf (" % d \ n ", 1 * n);
}

If (STR [0]>='0' && STR [0] <='9')
{
For (I=0, n=0; STR [I]!='\ 0'; I++)
{
N=n * 10 + STR [I] - '0';
}
Printf (" % d \ n ", n);
}

If (STR [0]!='+' && STR [0]!='-' && (STR [0] <='0' | | STR [0]>='9'))
{
Printf (" error! \n");
}

system("pause");
return 0;
}