# Define _ Crt_secure_no_warnings # Include <Stdio. h> # Include < String . H> Int Main (){ Char Str1 [ 255 ], Str2 [ 255 ]; Int Num1 [255 ] = { 0 }, Num2 [ 255 ] = { 0 }; // Used to store the subtrahend and subtrahend, and the shorter subtrahend Add the leading zeros. Int Dvalue [ 255 ] = { 0 }; Int Length1, leng2, length; Int I, J; Int Neg_flag = 0 ; // A negative flag Int Flag = 0 ; // Borrow sign Gets (str1); gets (str2); length1 = Strlen (str1); leng22. = Strlen (str2); Length = Length1> leng22? Length1: leng22; // Store two numbers in num [] For (I = length- 1 , J = length1- 1 ; J> = 0 ; I --, j -- ) {Num1 [I] = Str1 [J]- ' 0 ' ;} For (I = length- 1 , J = leng22- 1 ; J> = 0 ; I --, j --) {Num2 [I] = Str2 [J]- ' 0 ' ;} // Subtraction from the back to the back For (I = length- 1 ; I> = 0 ; I -- ) {Dvalue [I] = Flag + num1 [I]- Num2 [I]; If (Dvalue [I] < 0 ) {Dvalue [I] = Dvalue [I] + 10 ; Flag =- 1 ; // Indicates the borrow position } Else {Flag = 0 ;}} // If the above loop is exceeded, flag =-1 indicates that the difference is negative. // When the result is negative, the subsequent algorithm example is as follows: // For example, after the bitwise calculation, the difference value is 123, and the actual difference value is 1123-456. // Then, the difference between 667 and 1000 is the actual difference. Set a negative flag to neg_flag, and then use 1000-667. // That is, use 10 minus the second bit, and then use 9 minus the rest. If (Flag =- 1 ) {Neg_flag = 1 ; Dvalue [Length - 1 ] = 10 -Dvalue [length- 1 ]; For (I = length- 2 ; I> = 0 ; I -- ) {Dvalue [I] = 9 - Dvalue [I] ;}} // Skip the leading zero before outputting the difference value I = 0 ; While (Dvalue [I] =0 & (I < Length) {I ++ ;} // If the two numbers are equal, all the difference values are 0 and only one 0 is output. If (I = Length) {putchar ( ' 0 ' ); Return 0 ;} // If it is a negative number, the negative number is output first. If (Neg_flag = 1 ) {Putchar ( ' - ' );} For (; I <length; I ++ ) {Printf ( " % D " , Dvalue [I]);} Return 0 ;}