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)
#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;
}
Comments
Leave a comment