Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abhinav8925 patch 3 #390

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Matrix Prod.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <iostream>
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;
}
26 changes: 26 additions & 0 deletions Maximum Rod Cutting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#include <iostream>
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;
}
24 changes: 24 additions & 0 deletions Reverse string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <string>
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;
}