Knowee
Questions
Features
Study Tools

Mr.Alin is a physical master .During his sports hour he measured the height of the students. Now he wishes to make the students stands in increasing order of height. Write a c program to help Alin to accomplish this task.Input formatRead  a integer N representing the total number of studentsRead a array for storing height of studentsOutput formatDisplay the sorted heightsSample Input4549012123Sample OutputInput

Question

Mr.Alin is a physical master .During his sports hour he measured the height of the students. Now he wishes to make the students stands in increasing order of height. Write a c program to help Alin to accomplish this task.Input formatRead  a integer N representing the total number of studentsRead a array for storing height of studentsOutput formatDisplay the sorted heightsSample Input4549012123Sample OutputInput

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple C program that uses the bubble sort algorithm to sort the heights of the students in increasing order:

#include <stdio.h>

void bubbleSort(int arr[], int n) {
   for(int i = 0; i < n-1; i++) {     
       for (int j = 0; j < n-i-1; j++) { 
           if (arr[j] > arr[j+1]) {
              // Swap arr[j] and arr[j+1]
              int temp = arr[j];
              arr[j] = arr[j+1];
              arr[j+1] = temp;
           }
       }
   }
}

int main() {
   int i, n;
   printf("Enter the total number of students: ");
   scanf("%d", &n);
   int height[n];
   printf("Enter the heights of the students: ");
   for(i = 0; i < n; i++) {
      scanf("%d", &height[i]);
   }
   bubbleSort(height, n);
   printf("Heights in sorted order: ");
   for(i = 0; i < n; i++) {
      printf("%d ", height[i]);
   }
   return 0;
}

This program first reads the total number of students, then reads the heights of the students. It then sorts the heights using the bubble sort algorithm and finally prints the sorted heights.

This problem has been solved

Similar Questions

Problem StatementIn a computer science class, students are assigned unique identification letters based on their seating arrangement. Each student has a specific letter, and you are tasked with creating a program to sort these letters in ascending order using the bubble sort algorithm. The sorting should be based on their ASCII values. Input the total number of students and their assigned letters, then display the sorted list, allowing the students to easily identify their seating order.Input format :The first line of input consists of an integer N, representing the total number of students.The second line consists of N space-separated characters, each representing the unique identification letter assigned to a student.Output format :The output prints the sorted list of identification letters based on their ASCII values.Refer to the sample output for formatting specifications.Code constraints :1 ≤ N ≤ 15Each identification letter is a valid ASCII character.The input characters are case-sensitive.Sample test cases :Input 1 :5a y h j oOutput 1 :a h j o y Input 2 :7Q G Y O M N BOutput 2 :B G M N O Q Y Input 3 :8a e T V z X h KOutput 3 :K T V X a e h z

You work in the examination department of a school, and you've been given a task to sort the test scores of students in ascending order. The scores are stored in a list where each element represents the score of a student.Input FormatThe first line contains the integer N, the size of the array. The next line contains N space-separated integers.Constraints• 1<=N<=1000 • -1000<=a[i]<=1000Output FormatPrint the array as a row of space-separated integers in each iteration.Sample Input 01010 9 8 7 6 5 4 3 2 1Sample Output 05 9 8 7 6 10 4 3 2 15 4 8 7 6 10 9 3 2 15 4 3 7 6 10 9 8 2 15 4 3 2 6 10 9 8 7 15 4 3 2 1 10 9 8 7 63 4 5 2 1 10 9 8 7 63 2 5 4 1 10 9 8 7 61 2 3 4 5 10 9 8 7 61 2 3 4 5 10 9 8 7 61 2 3 4 5 10 9 8 7 61 2 3 4 5 8 9 10 7 61 2 3 4 5 8 7 10 9 61 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 10

C program to sort an array in ascending order

Single File Programming QuestionProblem Statement:Thiru is working on a grading system for his class of students. He needs a program that takes input for student scores, inserts a new score at the beginning and end of the existing scores, and then displays the modified list of scores.Write a program to help Thiru achieve this.Input format :The first line of input is an integer, the value n, indicating the number of elements in the array.The second line of input consists of n space-separated integers, representing the elements of the array arr[i].The third line of input consists of two integers M and P, representing the value to be inserted at the beginning and ending of the array, separated by a space.Output format :The output is a single line containing n + 2 space-separated integers, which represent the modified array after inserting the element at the beginning and ending of the existing scores.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases will fall under the following constraints:1 ≤ n ≤ 101 ≤ arr[i] ≤ 1001 ≤ M, P ≤ 100Sample test cases :Input 1 :53 4 5 6 72 8Output 1 :2 3 4 5 6 7 8 Input 2 :14590 78Output 2 :90 45 78 Input 3 :1098 37 48 28 16 18 20 100 25 131 19Output 3 :1 98 37 48 28 16 18 20 100 2

Max AltitudeImagine a pilot starting the flight from the ground and flying over a series of different points at different heights. You are given an array, where A[i] represents heights.Currently, if the pilot is at altitude X at ith point, and if he wants to reach (i+1)th point, his altitude will become X+A[i].The pilot starts at altitude 0 and wants to find the highest point he can reach during the entire journey. Your task is to print the highest altitude the pilot reaches.Input FormatThe first line of input contains an integer N. The second line of input contains N space-separated integers.Output FormatPrint the highest altitude the pilot can reach.Constraints1 <= N <= 1000-1000 <= A[i] <= 1000ExampleInput5-5 1 5 0 -7Output1ExplanationWhen the pilot started at point 0 his altitude was -5, when he moved to point 1 his altitude became (-5 + 1 = -4), at point 2 his altitude became(-4 + 5 = 1), at point 3his became altitude remains(1 + 0 = 1), and at point 4 his altitude became (1 + -7 = -6). The maximum altitude that he reached in his journey was 1.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.