下面内容是关于C++解决大数据的加法、减法、乘法以及阶乘的计算问题的内容,希望能对小伙伴也有用。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
{
int len;
assert( str != NULL );
len = 0;
{
len++;
}
return len;
}
{
}
{
int len1 = strlen(num1);
int len2 = strlen(num2);
int i, j, k, num;
num = get_allocate_num(&len1, &len2);
i = len1 - 1;
j = len2 - 1;
for (k = num - 1; k >= 0; k--) {
temp = num1[i--] + num2[j--] + flag;
temp_res[k] = temp - 0x3a;
flag = 0x01;
} else {
temp_res[k] = temp - 0x30;
flag = 0x0;
}
temp = num1[i--] + flag;
temp_res[k] = 0x30;
flag = 0x01;
} else {
temp_res[k] = temp;
flag = 0x0;
}
temp = num2[j--] + flag;
temp_res[k] = 0x30;
flag = 0x01;
} else {
temp_res[k] = temp;
flag = 0x0;
}
temp = flag;
temp_res[0] = 0x31;
strncpy(res, temp_res, num);
res[num] = '0';
strncpy(res, &temp_res[1], num-1);
res[num-1] = '0';
}
}
}
free(temp_res);
}
{
int i;
return 1;
return -1;
} else {
if (num1[i] > num2[i]) {
return 1;
} else if (num1[i] < num2[i]) {
return -1;
}
}
}
}
int len;
int i = 0;
if (res[0] == '-') {
i = 1;
while (res[i] == 0x30) {
i++;
}
if (i != 1) {
strncpy(temp, &res[i], len);
strncpy(&res[1], temp, len);
free(temp);
}
} else {
while (res[i] == 0x30) {
i++;
}
if (i != 0) {
strncpy(temp, &res[i], len);
strncpy(res, temp, len);
free(temp);
}
}
}
{
int len1 = strlen(num1);
i