C++大数相加
#pragma warning (disable:4996)
#include <iostream>
#include <string>
#include <conio.h>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <vector>
using namespace std;
int main(void) {
string num1 = "325326895666554425455787";
string num2 = "9323298957851632655699";
string result;
int p1 = num1.size() - 1;
int p2 = num2.size() - 1;
int carry = 0;
while (p1 >= 0 || p2 >= 0 || carry !=0) {
int x = (p1 >= 0) ? (num1[p1] - '0') : 0;
int y = (p2 >= 0) ? (num2[p2] - '0') : 0;
int sum = x + y + carry;
carry = sum / 10;
result =result + (char)(sum % 10 + '0');
p1--;
p2--;
}
int i = 0, j = result.size() - 1;
while (i < j) {
char temp = result[j];
result[j] = result[i];
result[i] = temp;
i++;
j--;
}
cout << num1 << "+" << num2 << "=" << result << endl;
system("pause");
return 0;
}