From d7b3c4fda7ef31614db95942db9bd0d495e0d9eb Mon Sep 17 00:00:00 2001 From: ABHINAV ANAND <95186533+abhinav8925@users.noreply.github.com> Date: Mon, 2 Oct 2023 01:10:58 +0530 Subject: [PATCH 1/5] Create Maximum Rod Cutting.cpp --- Maximum Rod Cutting.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Maximum Rod Cutting.cpp diff --git a/Maximum Rod Cutting.cpp b/Maximum Rod Cutting.cpp new file mode 100644 index 00000000..574c6250 --- /dev/null +++ b/Maximum Rod Cutting.cpp @@ -0,0 +1,26 @@ + +#include +using namespace std; + + +int max(int a, int b) { return (a > b)? a : b;} +int max(int a, int b, int c) { return max(a, max(b, c));} + + +int maxProd(int n) +{ + + if (n == 0 || n == 1) return 0; + + int max_val = 0; + for (int i = 1; i < n; i++) + max_val = max(max_val, i*(n-i), maxProd(n-i)*i); + + return max_val; +} + +int main() +{ + cout << "Maximum Product is " << maxProd(10); + return 0; +} From eca470043f1c372942a833bd24ce5a1ed454fb1d Mon Sep 17 00:00:00 2001 From: ABHINAV ANAND <95186533+abhinav8925@users.noreply.github.com> Date: Mon, 2 Oct 2023 01:12:14 +0530 Subject: [PATCH 2/5] Delete Maximum Rod Cutting.cpp --- Maximum Rod Cutting.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 Maximum Rod Cutting.cpp diff --git a/Maximum Rod Cutting.cpp b/Maximum Rod Cutting.cpp deleted file mode 100644 index 574c6250..00000000 --- a/Maximum Rod Cutting.cpp +++ /dev/null @@ -1,26 +0,0 @@ - -#include -using namespace std; - - -int max(int a, int b) { return (a > b)? a : b;} -int max(int a, int b, int c) { return max(a, max(b, c));} - - -int maxProd(int n) -{ - - if (n == 0 || n == 1) return 0; - - int max_val = 0; - for (int i = 1; i < n; i++) - max_val = max(max_val, i*(n-i), maxProd(n-i)*i); - - return max_val; -} - -int main() -{ - cout << "Maximum Product is " << maxProd(10); - return 0; -} From 25db031cb38b7d23321963ddb0278098ddadce49 Mon Sep 17 00:00:00 2001 From: ABHINAV ANAND <95186533+abhinav8925@users.noreply.github.com> Date: Mon, 2 Oct 2023 01:12:40 +0530 Subject: [PATCH 3/5] Create Maximum Rod Cutting.cpp --- Maximum Rod Cutting.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Maximum Rod Cutting.cpp diff --git a/Maximum Rod Cutting.cpp b/Maximum Rod Cutting.cpp new file mode 100644 index 00000000..574c6250 --- /dev/null +++ b/Maximum Rod Cutting.cpp @@ -0,0 +1,26 @@ + +#include +using namespace std; + + +int max(int a, int b) { return (a > b)? a : b;} +int max(int a, int b, int c) { return max(a, max(b, c));} + + +int maxProd(int n) +{ + + if (n == 0 || n == 1) return 0; + + int max_val = 0; + for (int i = 1; i < n; i++) + max_val = max(max_val, i*(n-i), maxProd(n-i)*i); + + return max_val; +} + +int main() +{ + cout << "Maximum Product is " << maxProd(10); + return 0; +} From 28a775b0f0af0525e1f8247fa85562387585a97e Mon Sep 17 00:00:00 2001 From: ABHINAV ANAND <95186533+abhinav8925@users.noreply.github.com> Date: Mon, 9 Oct 2023 17:35:05 +0530 Subject: [PATCH 4/5] Create Matrix Prod.cpp --- Matrix Prod.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Matrix Prod.cpp diff --git a/Matrix Prod.cpp b/Matrix Prod.cpp new file mode 100644 index 00000000..8b67068f --- /dev/null +++ b/Matrix Prod.cpp @@ -0,0 +1,54 @@ +#include +using namespace std; + +int main() { + int row1, col1, row2, col2; + + cout << "Enter the number of rows and columns of the first matrix: "; + cin >> row1 >> col1; + + cout << "Enter the number of rows and columns of the second matrix: "; + cin >> row2 >> col2; + + + if (col1 != row2) { + cout << "Matrix multiplication is not possible. Columns of the first matrix must be equal to rows of the second matrix." << endl; + return 1; + } + + cout << "Enter elements of the first matrix:" << endl; + int matrix1[row1][col1]; + for (int i = 0; i < row1; ++i) { + for (int j = 0; j < col1; ++j) { + cin >> matrix1[i][j]; + } + } + + cout << "Enter elements of the second matrix:" << endl; + int matrix2[row2][col2]; + for (int i = 0; i < row2; ++i) { + for (int j = 0; j < col2; ++j) { + cin >> matrix2[i][j]; + } + } + + int result[row1][col2] = {{0}}; + + for (int i = 0; i < row1; ++i) { + for (int j = 0; j < col2; ++j) { + for (int k = 0; k < col1; ++k) { + result[i][j] += matrix1[i][k] * matrix2[k][j]; + } + } + } + + cout << "Result of matrix multiplication:" << endl; + for (int i = 0; i < row1; ++i) { + for (int j = 0; j < col2; ++j) { + cout << result[i][j] << " "; + } + cout << endl; + } + + return 0; +} From 36ee7b53e0b06574516777870fb0423ece9c0f96 Mon Sep 17 00:00:00 2001 From: ABHINAV ANAND <95186533+abhinav8925@users.noreply.github.com> Date: Mon, 9 Oct 2023 17:36:52 +0530 Subject: [PATCH 5/5] Create Reverse string.cpp --- Reverse string.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Reverse string.cpp diff --git a/Reverse string.cpp b/Reverse string.cpp new file mode 100644 index 00000000..47d0ed33 --- /dev/null +++ b/Reverse string.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +int main() { + string str; + + // Input a string + cout << "Enter a string: "; + cin >> str; + + // Initialize an empty string to store the reversed string + string reversedStr = ""; + + // Reverse the string + for (int i = str.length() - 1; i >= 0; i--) { + reversedStr += str[i]; + } + + // Display the reversed string + cout << "Reversed string: " << reversedStr << endl; + + return 0; +}