From c599a0d9946fdd878f00453f8cb77a895ef7fee8 Mon Sep 17 00:00:00 2001 From: navyam Date: Mon, 30 Oct 2023 02:02:47 +0530 Subject: [PATCH 1/2] Created KaratsubaAlgorithm.c --- C/KaratsubaAlgorithm.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 C/KaratsubaAlgorithm.c diff --git a/C/KaratsubaAlgorithm.c b/C/KaratsubaAlgorithm.c new file mode 100644 index 0000000..bdf7303 --- /dev/null +++ b/C/KaratsubaAlgorithm.c @@ -0,0 +1,23 @@ +#include +#include +#include + +int KaratsubaAlgorithm(char* str1, char* str2){ + int i = 0, j = 0; + int num1 = 0, num2 = 0; + while (str1[i] != '\0') + { + num1 *= 2; + if (str1[i] == '0' || str1[i] == '1') num1 += str1[i] - '0'; + else return -1; + i++; + } + while (str2[j] != '\0') + { + num2 *= 2; + if (str2[j] == '0' || str2[j] == '1') num2 += str2[j] - '0'; + else return -1; + j++; + } + return num1 * num2; +} \ No newline at end of file From 4c6baeb6b5083ae2ffc29e0d9c3d40265a94b11c Mon Sep 17 00:00:00 2001 From: navyam Date: Mon, 30 Oct 2023 02:05:39 +0530 Subject: [PATCH 2/2] Updated C/README.md --- C/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/C/README.md b/C/README.md index 8b13789..131dde6 100644 --- a/C/README.md +++ b/C/README.md @@ -1 +1,2 @@ - +# KaratsubaAlgorithm +Karatsuba Algorithm takes two strings are function arguments. Converts them from binary string to a decimal value, and return product of the two numbers. If the numbers are invalid, or any character in the string is neither 1 nor 0, -1 is returned.