diff --git a/GeeksForGeeks/factorial.cpp b/GeeksForGeeks/factorial.cpp new file mode 100644 index 00000000..c8e0acdf --- /dev/null +++ b/GeeksForGeeks/factorial.cpp @@ -0,0 +1,14 @@ +#include +using namespace std; +int fact(int n){ + int ans=1; + for(int i=1;i>n; + int ans=fact(n); + cout< +using namespace std; + + +void insertionSort(int arr[], int n) +{ + int i, key, j; + for (i = 1; i < n; i++) + { + key = arr[i]; + j = i - 1; + + + while (j >= 0 && arr[j] > key) + { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } +} + + +void printArray(int arr[], int n) +{ + int i; + for (i = 0; i < n; i++) + cout << arr[i] << " "; + cout << endl; +} + + +int main() +{ + int arr[] = { 12, 11, 13, 5, 6 }; + int n = sizeof(arr) / sizeof(arr[0]); + + insertionSort(arr, n); + printArray(arr, n); + + return 0; +} + + diff --git a/GeeksForGeeks/lcs.cpp b/GeeksForGeeks/lcs.cpp new file mode 100644 index 00000000..fd41bfaa --- /dev/null +++ b/GeeksForGeeks/lcs.cpp @@ -0,0 +1,34 @@ +// The longest common subsequence in C++ + +#include +using namespace std; + +void lcsAlgo(char *S1, char *S2, int m, int n) { + int LCS_table[m + 1][n + 1]; + + + // Building the mtrix in bottom-up way + for (int i = 0; i <= m; i++) { + for (int j = 0; j <= n; j++) { + if (i == 0 || j == 0) + LCS_table[i][j] = 0; + else if (S1[i - 1] == S2[j - 1]) + LCS_table[i][j] = LCS_table[i - 1][j - 1] + 1; + else + LCS_table[i][j] = max(LCS_table[i - 1][j], LCS_table[i][j - 1]); + } + } + cout<<"Length of longest common subsequence : "<>S1>>S2; + int m = strlen(S1); + int n = strlen(S2); + + lcsAlgo(S1, S2, m, n); +} \ No newline at end of file diff --git a/Matrix_multiplication.cpp b/Matrix_multiplication.cpp new file mode 100644 index 00000000..629b799a --- /dev/null +++ b/Matrix_multiplication.cpp @@ -0,0 +1,62 @@ + //Matrix Multiplication +#include +using namespace std; +int main() +{ + int n,m,i,j,k,sum=0; + cout<<"Enter the number of rows and columns in matrix 1: "; + cin>>n>>m; + int a,b; + cout<<"Enter the number of rows and columns in matrix 2: "; + cin>>a>>b; + int m1[n][m],m2[a][b],m3[n][b]; + if(m!=a) + { + cout<<"We cannot multiply these two matrices"<>m1[i][j]; + } + } + cout<<"Enter the elements of matrix 2 : "<>m2[i][j]; + } + } + for(i = 0; i < n; ++i){ + for(j = 0; j < b; ++j) + { + m3[i][j]=0; + }} + for(i=0;i