diff --git a/C++/Factorial using Recursion.cpp b/C++/Factorial using Recursion.cpp new file mode 100644 index 00000000..3c7ef035 --- /dev/null +++ b/C++/Factorial using Recursion.cpp @@ -0,0 +1,27 @@ +#include + +using namespace std; + +//Time Complexity - O(N) + +int Recursive_Function(int a) +{ + if(a==0) + { + return 1; + } + else + { + return (a*Recursive_Function(a-1)); + } +} + +int main() +{ + int N; + cout<<"Enter the value of N:"; + cin >>N; + int Factorial = Recursive_Function(N); + cout<<"Factorial of "< + +using namespace std; + +//Time complexity - O(log N) + +//GCD +int GCD(int x,int y) +{ + if (x==0) + { + return y; + } + return GCD(y%x,x); +} + +//LCM +int LCM(int x1,int y1) +{ + int z = GCD(x1,y1); + int lcm = (x1*y1)/z; + return lcm; +} + + + +int main() +{ + int a,b; + cout<<"Enter the value of a and b:"; + cin>>a>>b; + int c = GCD(a,b); + int lcm_of_two_numbers = LCM(a,b); + cout< + +using namespace std; + +//Insertion Sort in the ascending order + +/*Performing Insertion Sort - We take first element in the array as sorted sublist +others are unsorted sublist and first element in the unsorted sublist, +we take it as temporary value and we compare it with all elements in the sorted sublist +if temporary value is less than last element in the sorted list we move that last element to +the temporary value with in that we take it as sorted sublist and we insert temp value in the sorted sublist*/ + +int Insertion_Sort(int arr[],int n) +{ + for(int i=1;i=0 && arr[j]>temp) + { + //To move the value which is greater than temp value + arr[j+1] = arr[j]; + + //Decrementing to check all the elements in the sorted sublist + j--; + } + + //If while loop condition(arr[j] > temp) fails then it take till temp as sorted sublist + arr[j+1] = temp; + } + + //Printing all the elements in the array After performing Insertion Sort + cout<<"\nAfter performing Insertion Sort\n"; + for(int j=0;j>size; + + //Array input + for(int i=0;i>arr[i]; + } + + //Printing all the elements in the array Before performing Insertion Sort + cout<<"\nBefore performing Insertion Sort\n"; + for(int j=0;j