Skip to content
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
14 changes: 14 additions & 0 deletions GeeksForGeeks/factorial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<bits/stdc++.h>
using namespace std;
int fact(int n){
int ans=1;
for(int i=1;i<n;i++){
ans*=i;
}
}
int main(){
int n;
cin>>n;
int ans=fact(n);
cout<<ans<<endl;
}
45 changes: 45 additions & 0 deletions GeeksForGeeks/insertionsort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

#include <bits/stdc++.h>
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;
}


34 changes: 34 additions & 0 deletions GeeksForGeeks/lcs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// The longest common subsequence in C++

#include <bits/stdc++.h>
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 : "<<LCS_table[m][n];


}

int main() {
char S1[100] ;
char S2[100];
cin>>S1>>S2;
int m = strlen(S1);
int n = strlen(S2);

lcsAlgo(S1, S2, m, n);
}
62 changes: 62 additions & 0 deletions Matrix_multiplication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//Matrix Multiplication
#include<iostream>
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"<<endl;
}
else{

cout<<"Enter elements of matrix 1: "<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>m1[i][j];
}
}
cout<<"Enter the elements of matrix 2 : "<<endl;
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
cin>>m2[i][j];
}
}
for(i = 0; i < n; ++i){
for(j = 0; j < b; ++j)
{
m3[i][j]=0;
}}
for(i=0;i<n;i++)
{
for(j=0;j<b;j++)
{
sum=0;
for(k=0;k<n;k++)
{
m3[i][j]+=m1[i][k]*m2[k][j];
}

}
}
for(i=0;i<n;i++)
{
for(j=0;j<b;j++)
{
cout<<m3[i][j]<<" ";
}
cout<<endl;
}

}
}