Код: Выделить всё
#include
#include
using std::string, std::cout, std::endl; //Include for debug outputs
#include "bigInt.h"
Any advice would be much appreciated! It seems I'm messing up somewhere with the logic for the carry but I can't figure out how...
char character(int x) {
// Converts integer 0-9 to corresponding character '0-9'
return '0' + x;
}
int number(char ch) {
// Converts character '0-9' to corresponding integer 0-9 by subtracting ASCII value of 0
if (ch >= '0' && ch nB ? nA : nB;
if (maxLen + 5 > nC) {
return false; // Insufficient space
}
// Initialize carry and index variables
int carry = 0;
int k = 0;
for(int i=0;i 0; ++i) {
int digitA = i < nA ? A[i] : 0;
int digitB = i < nB ? B[i] : 0;
int sum = digitA + digitB + carry;
carry = sum / 10; // Determine the carry for the next iteration
C[k] = sum % 10; // Store the result digit
k++;
}
// Update the length of the result array
nC = k;
reverseArray(C,nC);
return true; // Addition successful
}
bool fromStringToArray(const string& str, int A[], int size, int& n) {
n = str.length();
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78537483/adding-2-big-integers-via-c-array[/url]
Мобильная версия