Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,943 questions

55,787 answers

573 users

How to sort the part of an array in C

1 Answer

0 votes
#include <stdio.h>

// Function to sort a portion of the array from start to end (inclusive)
void partialSort(int arr[], int start, int end) {
    int temp;
    for (int i = start; i <= end; i++) {
        for (int j = i + 1; j <= end; j++) {
            if (arr[j] < arr[i]) {
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
    }
}

int main() {
    int arr[] = {15, 6, 19, 8, 3, 7, 9, 1, 4};
    int size = sizeof(arr) / sizeof(arr[0]);

    // Sort elements from index 2 to 6
    partialSort(arr, 2, 6);

    // Print the updated array
    for (int i = 0; i < size; i++) {
        printf("%d ", arr[i]);
    }
    printf("\n");

    return 0;
}



/*
run:
 
15 6 3 7 8 9 19 1 4 
 
*/

 



answered Aug 12, 2025 by avibootz
...