Answer to Question #214211 in C for ABHINEET GAUR

Question #214211

Mr. Sayam Bharamraj is a school teacher and is a class teacher of section 9, in the initial days he was made to take care of kids during the prayers. He has to make students to stand in the line height-wise. There were 10 students in his section. Help Mr. Sayam Bharamraj to arrange the students in the lowest to the highest height.

(Hint: Perform Bubble sort, Reading the height of the students)


1
Expert's answer
2021-07-07T04:09:26-0400
#include <stdio.h>


#define N 10


void BubbleSort(int a[])
{
    int i, j, tmp, wasOrderd;


    for (i=0; i<N-1; i++) {
        wasOrderd = 1;
        for (j=0; j<N-1; j++) {
            if (a[j] > a[j+1]) {
                tmp = a[j];
                a[j] = a[j+1];
                a[j+1] = tmp;
                wasOrderd = 0;
            }
        }


        if (wasOrderd) {
            break;
        }
    }
}


int main() {
    int height[N];
    int i;


    for (i=0; i<N; i++) {
        printf("Enter height of %d-th student: ", i+1);
        scanf("%d", &height[i]);
    }


    BubbleSort(height);


    printf("The height-wise line is:\n");
    for (i=0; i<N; i++) {
        printf("%d ", height[i]);
    }
    printf("\n");


    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