#include <string.h>
void add(char a[], char b[], char result[], int maxLength) {
int carry = 0;
for(int i = maxLength - 1; i >= 0; i--) {
int sum = (a[i] - '0') + (b[i] - '0') + carry;
result[i] = (sum % 10) + '0';
carry = sum / 10;
}
if(carry) {
Serial.println("Overflow error");
}
}
void multiply(char a[], char b[], char result[], int maxLength) {
memset(result, '0', maxLength);
for(int i = strlen(a) - 1; i >= 0; i--) {
int carry = 0;
for(int j = strlen(b) - 1; j >= 0; j--) {
int product = (a[i] - '0') * (b[j] - '0') + (result[i + j + 1] - '0') + carry;
result[i + j + 1] = (product % 10) + '0';
carry = product / 10;
}
result[i] += carry;
}
}
void setup() {
Serial.begin(9600);
char a[] = "1234567890987654321";
char b[] = "9876543210123456789";
int maxLength = strlen(a) + strlen(b) + 1;
char result[maxLength];
multiply(a, b, result, maxLength);
Serial.print("a * b = ");
Serial.println(result);
}
void loop() {
// Do nothing
}