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

Sure, here is a simple C program that sorts an array of 10 roll numbers:

#include <stdio.h>

void sort(int a[], int n) {
   int i, j, temp;
   for (i = 0; i < n-1; i++) {     
       for (j = 0; j < n-i-1; j++) { 
           if (a[j] > a[j+1]) {
              temp = a[j];
              a[j] = a[j+1];
              a[j+1] = temp;
           }
       }
   }
}

int main() {
   int rollnos[10] = {8,7,1,0,9,1,3,2,5,4}, i;
   int n = sizeof(rollnos)/sizeof(rollnos[0]);
   
   sort(rollnos, n);
   
   printf("Sorted roll numbers are: \n");
   for(i = 0; i < n; i++)
      printf("%d ", rollnos[i]);
   
   return 0;
}

This program uses the Bubble Sort algorithm to sort the roll numbers. The sort function takes an array and its size as input, and sorts the array in ascending order. The main function initializes the roll numbers, calls the sort function to sort them, and then prints the sorted roll numbers.

This problem has been solved

Similar Questions

complete the precode to perform sorting operations using a pointer to functions input: assign an array of values as {5, 2, 8, 1, 6} exactly,  assign M value based on input given above.and declare a pointer variable to  assign this array,call the function swap to perform the bubble sort and output will be12568

C program to sort an array in ascending order

Program to implement heap sort

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

Write a functional program that sorts 10 input integers (signed) using either bubble sort orselection sort algorithm. The output window must show both unsorted array of integers andsorted array of integers.

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.