I am super new to programming and I am having a problem with one of the questions where i am supposed to write a C program to let the user enter some numbers and sort the entered elements and find the median of it. And it should stop getting inputs once the user presses enter. this is my code and idk where it went wrong(btw sorry for asking such a simple question)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
int i = 0;
int j,k,m,num;
int arr[20];
while(i<20 )
{
printf("Enter a number: ");
scanf("%d",&num);
if(num == '\n') break;
arr[i] = num;
i++;
}
n = sizeof(arr)/sizeof(arr[0]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i] < arr[j])
{
k = arr[i];
arr[i] = arr[j];
arr[j] = k;
}
}
}
if(n%2 != 0)
{
printf("The median is %d", arr[n/2] ) ;
}
else printf("The median is %.2f", arr[(n-1)/2] + arr[n/2]/2.0);
return 0;
}