Posts

Showing posts from September, 2025

insertion sort using c language

 #include <stdio.h> int main() {     int n, i, j, temp;     int arr[100];     // Input: Number of elements     printf("Enter number of elements: ");     scanf("%d", &n);     // Input: Array elements     printf("Enter %d integers: ", n);     for(i = 0; i < n; i++)         scanf("%d", &arr[i]);     // Insertion Sort Algorithm     for(i = 1; i < n; i++) {         temp = arr[i];         j = i - 1;         while(j >= 0 && arr[j] > temp) {             arr[j + 1] = arr[j];             j = j - 1;         }         arr[j + 1] = temp;     }     // Output: Sorted array     printf("Sorted array: ");     for(i = 0; i < n; i++)     ...

Selection sort using c language

 #include <stdio.h> int main() {     int n, i, j, min, temp;     int arr[100];     // Input: Number of elements     printf("Enter number of elements: ");     scanf("%d", &n);     // Input: Array elements     printf("Enter %d integers: ", n);     for (i = 0; i < n; i++)         scanf("%d", &arr[i]);     // Selection Sort Algorithm     for (i = 0; i < n - 1; i++) {         min = i;         for (j = i + 1; j < n; j++)             if (arr[j] < arr[min])                 min = j;         // Swap         temp = arr[i];         arr[i] = arr[min];         arr[min] = temp;     }     // Output: Sorted array     printf("Sorted array: ...

Merge sort program using c language

https://www.programiz.com/online-compiler/60moA4PIpU4GL  #include <stdio.h> // Function to display the array (can show full array or subpart) void displayArray(int a[], int start, int end) {     for (int i = start; i < end; i++)         printf("%d ", a[i]);     printf(" "); } // Selection Sort Function void selectionSort(int a[], int n) {     for (int i = 0; i < n - 1; i++) {         int min = i;         // Find the minimum element in remaining unsorted array         for (int j = i + 1; j < n; j++) {             if (a[j] < a[min])                 min = j;         }         // Swap found minimum element with the first element         if (min != i) {             int temp = a[min];      ...