This is an ascending order sorting problem from descending order
#include <stdio.h> int main() { int n,i; printf("Enter the size of the array : "); scanf("%d",&n); int arr[n]; printf("enter the elements in the array : "); for(i=0;i<n;i++) { scanf("%d",&arr[i]); } for(i=0;i<n;i++) { printf("the elements entered at index %d: %d\n",i,arr[i]); } int temp=0; printf("the sorted array is : "); for(i=0;i<n;i++) { if(arr[i]>arr[i+1]){ temp=arr[i]; arr[i]=arr[i+1]; arr[i+1]=temp; } } for(i=0;i<n;i++){ printf("%d",arr[i]); } return 0; } Input: 10 9 8 7 6 5 Expected output : 5 6 7 8 9 10 Original output : 9 8 7 6 5 01 Whats the wrong here ? Why it's only changing the first element why not the whole thing?