void setup() {
Serial.begin(9600);
}
void loop() {
// Define two large numbers as character arrays
char num1[] = "9057917594432764628576357384957674891234567892567324516898356";
char num2[] = "8173295724676237656943720173645857659876543213890182645738928";
// Determine the length of each number
int len1 = strlen(num1);
int len2 = strlen(num2);
Serial.print(len1);
Serial.println();
// Create a result array with space for the maximum number of digits
int resultSize = len1 + len2;
int result[resultSize];
memset(result, 0, sizeof(result)); // initialize result array with zeros
// Multiply each digit of num1 by each digit of num2
for (int i = 0; i < len1; i++) {
int digit1 = num1[len1-i-1] - '0'; // convert char to int and read from right to left
int carry = 0;
for (int j = 0; j < len2; j++) {
int digit2 = num2[len2-j-1] - '0'; // convert char to int and read from right to left
int product = digit1 * digit2 + carry + result[i+j];
carry = product / 10;
result[i+j] = product % 10;
}
if (carry > 0) {
result[i+len2] += carry;
}
}
// Trim leading zeros from result
int resultEnd = resultSize-1;
while (result[resultEnd] == 0 && resultEnd > 0) {
resultEnd--;
}
// Print the result to the Serial Monitor
Serial.print("Result: ");
for (int i = resultEnd; i >= 0; i--) {
Serial.print(result[i]);
}
Serial.println();
delay(1000);
}