Answer to Question #293576 in C for Gokul

Question #293576

Sorting is a process of arranging numbers according to a certain


sequence. Write a C functions to read n integer values, sorting


process and display the arranged numbers.

1
Expert's answer
2022-02-03T03:59:35-0500
#include <stdio.h>


#define N 100


void sort(int* arr, int n) {
    int i, j, tmp;


    for (i=0; i<n-1; i++) {
        for (j=i+1; j<n; j++) {
            if (arr[j] < arr[i]) {
                tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
            }
        }
    }
}


int main() {
    int n, i;
    int arr[N];


    printf("Enter n: ");
    scanf("%d", &n);


    printf("Enter %d integers: ", n);
    for (i=0; i<n; i++) {
        scanf("%d", &arr[i]);
    }


    sort(arr, n);
    printf("Sorted array:\n");
    for (i=0; i<n; i++) {
        printf("%d ", arr[i]);
    }


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS