要求实现函数:
void AddLongInteger(char * pcAddend, char * pcAugend, char * pcAddResult);
输入参数:
char * pcAddend:加数
char * pcAugend:被加数
char * pcAddResult:加法结果
返回值:无
我设计了一个函数
void AddLongInteger(char * pcAddend, char * pcAugend, char * pcAddResult)
{
int pcAddend_len = 0,pcAugend_len = 0,pcAddResult_len = 0;
char* temp_s1 = pcAddend,*temp_s2 = pcAugend;
while(*temp_s1)
{
pcAddend_len++;
temp_s1++;
}
while(*temp_s2)
{
pcAugend_len++;
temp_s2++;
}
char temp_pcAddresult[100] = {0};
int carry = 0;
int k=99;
for(int i=pcAddend_len-1,j=pcAugend_len-1;i>=0||j>=0;i--,j--)
{
int temp_num;
if (i<0)
{ temp_num = int(pcAugend[j]-'0') + carry; }
else if (j<0)
{ temp_num = int(pcAddend[i] - '0') + carry; }
else
{ temp_num = int(pcAddend[i] - '0') + int(pcAugend[j]-'0') + carry; }
temp_pcAddresult[k--] = (char)(temp_num%10) + '0';
carry = temp_num/10;
}
temp_pcAddresult[k] = (char)carry + '0';
for(int i=0;i<100;i++)
{
if (temp_pcAddresult[i]!='0'&&temp_pcAddresult[i]!=0)
{
pcAddResult_len = 100-i;
break;
}
}
char* temp_u = pcAddResult;
for(int i=0;i<pcAddResult_len;i++)
{
*temp_u = temp_pcAddresult[100-pcAddResult_len+i];
temp_u++;
}
}
但是传不出子函数中的结果,求大神指点!