Computer Science, asked by Sunita1234, 1 year ago

Write a program in single dimensional array to select 10 numbers and arrange them
in an ascending order by using selection sort technique.

Answers

Answered by BrainlyTech
6

Hello there here is what got for you today...

Write a program in single dimensional array to select 10 numbers and arrange them  in an ascending order by using selection sort technique.

/**

* C program to sort elements of array in ascending order

*/

#include <stdio.h>

#define MAX_SIZE 100    // Maximum array size

int main()

{

   int arr[MAX_SIZE];

   int size;

   int i, j, temp;

   /* Input size of array */

   printf("Enter size of array: ");

   scanf("%d", &size);

   /* Input elements in array */

   printf("Enter elements in array: ");

   for(i=0; i<size; i++)

   {

       scanf("%d", &arr[i]);

   }

   for(i=0; i<size; i++)

   {

       /*  

        * Place currently selected element array[i]

        * to its correct place.

        */

       for(j=i+1; j<size; j++)

       {

           /*  

            * Swap if currently selected array element

            * is not at its correct position.

            */

           if(arr[i] > arr[j])

           {

               temp     = arr[i];

               arr[i] = arr[j];

               arr[j] = temp;

           }

       }

   }

   /* Print the sorted array */

   printf("\nElements of array in ascending order: ");

   for(i=0; i<size; i++)

   {

       printf("%d\t", arr[i]);

   }

   return 0;

}

Hope this helps you!!

Have a good day!!!

:)

Similar questions