Answer to Question #274620 in C for Lucky

Question #274620

Write a C program for Bubble Sort Algorithm for the descending order in


CodeBlocks using a user defined function.

1
Expert's answer
2021-12-02T07:31:05-0500
#include <stdio.h>
#include <stdlib.h>


void bubble_sort(int A[], int n) {
	int temp,i,k;
	for(k = 0; k< n-1; k++) {
		for(i = 0; i < n-k-1; i++) {
			if(A[ i ] < A[ i+1] ) {
				temp = A[ i ];
				A[ i ] = A[ i+1 ];
				A[ i + 1] = temp;
			}
		}
	}
}


int main(){
	int arrayNumbers[]={5,4,78,6,1,2,8,6,44,56};
	int i;
	int n=10;
	printf("Current numbers:\n");
	for(i = 0; i < n; i++) {
		printf("%d ",arrayNumbers[i]);
	}
	printf("\n\nSorted numbers:\n");
	bubble_sort(arrayNumbers,n);
	for(i = 0; i < n; i++) {
		printf("%d ",arrayNumbers[i]);
	}
	getchar();
	getchar();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS