WAP to sort an array in ascending order. Issue: After Sorting the array getting the garbage value in the compiler. Also when done without a function compiler return nothing
#include<stdio.h>
//Global Decleration
int i, j, size;
//Function for bubble sort
int bubblesort(int arr[size]){
int temp;
printf("The numbers arranged in ascending order are given below: \n");
for(i=0;i<size-1;i++){
for(j=0;j<size-1-i;j++){
if(arr[j]>arr[j+1]){
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
for(j=0;j<size;j++)
printf("%d\n",arr[j]);
}
int main(){
int size, arr[size];
printf("Enter the number of elements of the array: \n");
scanf("%d", &size);
printf("Enter the numbers: \n");
for(i=0;i<size;i++){
scanf("%d", &arr[i]);
}
bubblesort(arr[size]);
}