What,s wrong with this sorting algo? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What,s wrong with this sorting algo?

#include <stdio.h> int main() { int a[10]= {5, 4, 10, 1, 6, 2}, b[10]; int n, count=0; scanf("%d",&n); //Ascending order sort for(int i=0; i<n; i++){ //write sorted array a into array b b[i]= 0; } for(int i=0; i<n; i++){ scanf("%d", &a[i]); } for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ if(a[i]>a[j]) count++; } b[count]= a[i]; } for(int i=0; i<n; i++){ printf("%d ", b[i]); } return 0; }

30th Apr 2020, 9:55 AM
Tom
Tom - avatar
1 Answer
+ 2
Thank you, guys! got it After this, the count is not returned to 0. It works now!
30th Apr 2020, 10:00 AM
Tom
Tom - avatar