Code Snippets 4 U
#include < stdio.h > 
#include < stdlib.h >

  int main() {
    int total;
    printf("Enter the total number of elements\n");
    scanf("%d", & total);
    int arr[total];
    for (int temp = 0; temp < total; temp++) {
      printf("Enter the number %d : ", temp + 1);
      scanf("%d", arr + temp);
    }
    // selection sort

    for (int i = 0; i < total; i++) {
      // find the minimum
      int min = i;
      for (int j = i; j < total; j++) {
        if (arr[min] > arr[j]) {
          min = j;
        }
      }
      // swap the minimum with i
      int tempVar = arr[min];
      arr[min] = arr[i];
      arr[i] = tempVar;
    }
    // print the numbers

    for (int i = 0; i < total; i++) {
      printf("%d,", arr[i]);
    }
    return 0;
  }

Leave a Reply

Your email address will not be published. Required fields are marked *

sixty two − sixty =