Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C how to define integer variables and limit the number of input digits?
C how to define integer variables and limit the number of input digits?
Assume that the number of qualified digits is n (n

int? I, n, numbers, symbols? =? 1,num? =? 0;

scanf("%d ",& ampn); ? //? Read limit bit

For (me? =? 0; ? Me? & lt? n; ? ++i)? {

Numbers? =? getchar();

If (numbers? =? \n ')? Break; ? //? End of reading

If (numbers? =? '+')? Sign? =? 1;

Or what? If (numbers? =? '-')? Sign? =? - 1;

If (numbers? & gt=? '0'? & amp& amp? Numbers? & lt=? '9')

num? =? 10? *? num? +? Numbers? -? '0';

}

num? *=? Sign; ? //? This is the read-in integer.