guys please help me to find the sigsegv runtime error in this c code

,

#include<stdio.h>
int main()
{int arr[100],i,n,t,j;
scanf("%d",&n);
for(i=0;i<n;i++)
{scanf("%d",&arr[i]);
}
for(i=0;i<n;i++)
{for(j=i+1;j<n;j++)
{if(arr[i]>arr[j])
{t=arr[i];
arr[i]=arr[j];
arr[j]=t;
}}}
for(i=0;i<n;i++)
printf("%d\n",arr[i]);
return(0);
}

why int arr[100] ?

I can see you are solving Turbo sort.

yes it is turbo sort,and i am using arr[100] so that the user can give input 100 elements …i have run this code on turbo c and its runs perfectly in it!!! so why am i getting runtime error in this??

i am using arr[100] so that the user can give input 100 elements

…and in problem statement it’s written, that there can be up to one million elements…

1 Like

i have also done it by taking 1 million elements but then its show time limit exeeded…

because your sorting algorithm is quite slow. Read about Quicksort and Mergesort

Even that might give a TLE. Try counting sort.