diff --git a/C++/merge_sort.cpp b/C++/merge_sort.cpp new file mode 100644 index 00000000..0971dfe8 --- /dev/null +++ b/C++/merge_sort.cpp @@ -0,0 +1,66 @@ +#include +using namespace std; +void swapping(int &a, int &b) { + int temp; + temp = a; + a = b; + b = temp; +} +void display(int *array, int size) { + for(int i = 0; i> n; + int arr[n]; //create an array with given number of elements + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + display(arr, n); + mergeSort(arr, 0, n-1); //(n-1) for last index + cout << "Array after Sorting: "; + display(arr, n); +} \ No newline at end of file diff --git a/C++/quick_sort.cpp b/C++/quick_sort.cpp new file mode 100644 index 00000000..c8558f7b --- /dev/null +++ b/C++/quick_sort.cpp @@ -0,0 +1,69 @@ +#include +using namespace std; +void swapping(int &a, int &b) { //swap the content of a and b + int temp; + temp = a; + a = b; + b = temp; +} +void display(int *array, int size) { + for(int i = 0; i> n; + int arr[n]; //create an array with given number of elements + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + display(arr, n); + mergeSort(arr, 0, n-1); //(n-1) for last index + cout << "Array after Sorting: "; + display(arr, n); +} \ No newline at end of file diff --git a/Java/factorial.java b/Java/factorial.java new file mode 100644 index 00000000..c9fafa3f --- /dev/null +++ b/Java/factorial.java @@ -0,0 +1,10 @@ +class factorial{ + public static void main(String args[]){ + int i,fact=1; + int number=5;//It is the number to calculate factorial + for(i=1;i<=number;i++){ + fact=fact*i; + } + System.out.println("Factorial of "+number+" is: "+fact); + } +} \ No newline at end of file