Computer Science, asked by jerinaxavier0, 20 hours ago

write a c program to accept 1-D array from the user and perform bubble sort in descending order.​

Answers

Answered by naveenkarthickr1
0

Answer:

please mark me as brainlist

hope it's helpful l

Explanation:

Bubble sort in C to arrange numbers in ascending order; you can modify it for descending order and can also sort strings. The bubble sort algorithm isn't efficient as its both average-case as well as worst-case complexity are O(n2).

Attachments:
Answered by samarthkrv
0

Answer:

#include<stdio.h>

void bubble_sort(int arr[] , int len)

{

for(int i = 0; i < len; i++)

{

for(int j = 0; j < len; j++)

{

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

 {

 int temp = arr[i];

 arr[i] = arr[j];

 arr[j] = temp;

 }

}

}

}

int main()

{

int len;

printf("Enter the number of elements in the array:");

scanf("%d" , &len);

int arr[len];

printf("Enter all %d elements in the array: \n" , len);

  for(int i = 0; i < len; i++){

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

  }

printf("---THE ORIGINAL ARRAY--- \n");

  for(int i = 0; i < len; i++){

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

  }

bubble_sort(arr,len);

printf("\n---AFTER SORTING IN DESCENDING ORDER--- \n");

  for(int i = 0; i < len; i++){

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

  }

return 0;

}

Explanation:

Similar questions