Submission
Status:
PPPPPPPPPP
Score: 100
User: Cmoss9
Problemset: I.Quick Math
Language: c
Time: 0.009 second
Submitted On: 2024-10-14 12:59:50
#include <stdio.h>
int stringlength(char arr[]) {
int index = 0;
while (arr[index] != '\0') {
index++;
}
return index;
}
int main() {
char a[100000];
char b[100000];
scanf("%s", a);
scanf("%s", b);
int lengtha = stringlength(a);
int lengthb = stringlength(b);
int lengthresult = lengtha + lengthb;
char result[lengthresult + 1];
for (int i = 0; i < lengthresult; i++) {
result[i] = '0';
}
result[lengthresult] = '\0';
for (int i = lengtha - 1; i >= 0; i--) {
for (int j = lengthb - 1; j >= 0; j--) {
int mul = (a[i] - '0') * (b[j] - '0');
int p1 = i + j;
int p2 = i + j + 1;
int sum = mul + (result[p2] - '0');
result[p2] = '0' + sum % 10;
result[p1] = '0' + (result[p1] - '0' + sum / 10);
if (result[p1] > '9') {
int carry = (result[p1] - '0') / 10;
result[p1] = '0' + (result[p1] - '0') % 10;
result[p1 - 1] = '0' + (result[p1 - 1] - '0' + carry);
}
}
}
int start = 0;
while (start < lengthresult && result[start] == '0') {
start++;
}
for (int i = start; i < lengthresult; i++) {
printf("%c", result[i]);
}
printf("\n");
}