Knowee
Questions
Features
Study Tools

Write a program using C language that sorts the 10 rollno,s of your class placed in an array of size 10?Input:87109132546 Output:12345678910

Question

Write a program using C language that sorts the 10 rollno,s of your class placed in an array of size 10?

Input: 87109132546
Output: 12345678910

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

Solution

Here’s a simple C program that sorts the roll numbers stored in an array of size 10. The program uses the bubble sort algorithm for sorting the roll numbers.

C Program to Sort Roll Numbers

#include <stdio.h>

int main() {
    int rollno[10], i, j, temp;

    // Input 10 roll numbers
    printf("Enter 10 roll numbers: ");
    for(i = 0; i < 10; i++) {
        scanf("%d", &rollno[i]);
    }

    // Bubble sort algorithm
    for(i = 0; i < 10 - 1; i++) {
        for(j = 0; j < 10 - i - 1; j++) {
            if(rollno[j] > rollno[j + 1]) {
                // Swap
                temp = rollno[j];
                rollno[j] = rollno[j + 1];
                rollno[j + 1] = temp;
            }
        }
    }

    // Output sorted roll numbers
    printf("Sorted roll numbers: ");
    for(i = 0; i < 10; i++) {
        printf("%d ", rollno[i]);
    }
    
    return 0;
}

How the Program Works

  1. Input: The program prompts the user to enter 10 roll numbers which are stored in an array.
  2. Sorting: The program implements the bubble sort algorithm to sort the roll numbers in ascending order.
  3. Output: Finally, it prints the sorted roll numbers.

Final Answer

Use the above code to sort roll numbers. Input: 8710913254 will yield Output: 1 2 3 4 5 7 8 9 10.

This problem has been solved

Similar Questions

Write a C++ program that will input 10 array elements and output the following.elements in original orderelements in reverse ordersmallest element

Write a class to sort the given set of integers in descending order. Include a try block tolocate the array index out of bounds exception and catch it.

Consider the given numbers and arrange in an increasing order using sorting algorithm. Show all the sweeps. 80 9 30 20 7

Sort the given list of numbers in ascending order. Demonstrate the first pass/sweep sort algorithm. 43 18 9 76 89 1

Write a java program to implement interfaces sort the set of numbers and a set of strings in a given array

1/1

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.