diff --git a/Programming/C++/Insertionsort.cpp b/Programming/C++/Insertionsort.cpp new file mode 100644 index 0000000..e9da636 --- /dev/null +++ b/Programming/C++/Insertionsort.cpp @@ -0,0 +1,37 @@ +#include +using namespace std; +//Insertion sort +int main(){ + + int n,comp=0,swap=0; + cout<<"Enter the no. of elements: "; + cin>>n; + + +int arr[n]; + cout<<"Enter the unsorted array: "; + for(int i=0;i>arr[i]; + } + +for(int i=1;icurrent && j>=0){ + arr[j+1]=arr[j]; + j--; + comp++; + } + arr[j+1]=current; + swap++; +} + + cout<<"Yor sorted array: ["; + for(int i=0;i0) { + for(int i=1;i<=num;i++){ + factorial*=i; + } + System.out.println("Factorial of "+num+" is "+factorial); + } + else if(num<0){ + System.out.println("Not Defined "); + } + else{ + System.out.println(" factorial is 0 "); + } + } +}