Help me please. There is a code, you need to sort the numbers in ascending order ... here’s the program, here in descending order, I just can’t figure out how to do it in ascending order.

#include <stdio.h> #include <conio.h> int main () { int p[50]; int i, n, j; int count = 1; float res; printf("Size= "); scanf("%u",&n); printf("\nEnter elements: \n"); for (int i = 0; i < n; i++) { printf("Element[%d]= ", i+1); scanf("%u", &p[i]); } int temp=p[0]; for (i=1; i<n; i++) if(p[i]!=temp){ for (j=i+1; j<n; j++) if(p[i]==p[j]) p[j]=temp; count++; } printf("\nYou Mas:\n"); for (i=0; i<n; i++) printf("%i ", p[i]); printf("\n"); count=0; for (i=1; i<n; i++) if (p[i]!=p[0]) p[++count]=p[i]; printf("\nAfter del:\n"); for (i=0; i <= count; i++) printf("%i ", p[i]); printf("\nSort mas: \n"); for (int i = 0; i <= count; i++) for (int j = i+1; j <= count; j++) if (p[i] < p[j]){ int buf = p[i]; p[i] = p[j]; p[j] = buf; } for (int i = 0; i <= count; i++) printf("%i ", p[i]); getch(); return 0; } 
  • four
    @ Dunno-dropout if you wrote this program yourself, then obviously you should understand how it works. If someone wrote it for you, then it makes sense to ask the author about the principle of her work - DreamChild
  • for (int i = 0; i <= count; i ++) for (int j = i + 1; j <= count; j ++) if (p [i] !!!!> !!!! p [j]) {int buf = p [i]; p [i] = p [j]; p [j] = buf; } I put the exclamation marks where to change, try ... - zesen

0