大整数的运算帮忙看看那里错了啊
#include <stdio.h>#include <string.h>
void ReadBigInt(char number[])
{
int length = 0, index = 0;
printf("请输入大整数: ");
fflush(stdin);
gets(number);
length = strlen(number);
for(index = 0; index < length / 2; index++)
{
int tmp = number[index];
number[index] = number[length - 1 - index];
number[length - 1 - index] = tmp;
}
}
void PrintBigInt(char number[])
{
int index = 0,length = strlen(number);
for(index = length -1 ;index >= 0;index--)
{
printf("%c", number[index]);
}
}
void AddString(char small[], char big[], char result[])
{
int i = 0 ,smallLen = strlen(small),
bigLen = strlen(big);
int carry =0;
for(i = 0; i < smallLen; i++)
{
result[i] = small[i] - '0'
+ big[i] - '0' + carry;
carry = result[i] / 10;
result[i] = result[i] % 10 + '0';
}
for(; i < bigLen; i++)
{
result[i] = big[i] - '0' + carry;
carry = result[i] / 10;
result[i] = result[i] % 10 + '0';
}
if(carry)
result[i++] = carry + '0';
result[i] = '\0';
}
void Add(char left[], char right[], char result[])
{
int leftLen = strlen(left);
int rightLen = strlen(right);
if(leftLen > rightLen)
{
AddString(right, left, result);
}
else
{
AddString(left, right,result);
}
}
void Substract(char big[], char small[], char result[])
{
int borrow = 0;
int index = 0;
int smallLength = strlen(small);
int bigLength = strlen(big);
for(; index < smallLength; index++)
{
result[index] = (big[index] - '0') -
(small[index] - '0') - borrow;
if(result[index] < 0)
{
result[index] =result[index] + 10 ;
borrow = 1;
}
else
borrow = 0;
result[index] = result[index] + '0';
}
for(; index < bigLength; index++)
{
result[index] = (big[index] - '0') - borrow;
if(result[index] < 0)
{
result[index] =result[index] + 10 ;
borrow = 1;
}
else
borrow = 0;
result[index] = result[index] + '0';
}
result[index] = 0;
}
void main()
{
char choice = 0;
char left[1000] = {0}, right[1000] = {0},
result[1000] = {0};
printf("请输入运算符: (+,-,*,/)");
scanf("%c", &choice);
ReadBigInt(left);
ReadBigInt(right);
Substract(left,right,result);
PrintBigInt(result);
}