RE (SIGSEV) in SMPAIR


I was using bubble sort even though i know time complexity is high but while submitting i though i would get TLE but i got runtime error SIGSEGV can tell me why?
here is code

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

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

ok

thnx for helping!@ssjgz

1 Like

Your initialising arr using the uninitialised variable i:

        int arr[i] ;
2 Likes

Thanks a lot @ssjgz
error rectified :slight_smile:

1 Like