You are not logged in. Please login at www.codechef.com to post your questions!

×

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);
 }

asked 05 Oct '14, 19:15

rahul6272's gravatar image

1★rahul6272
11
accept rate: 0%

edited 06 Oct '14, 23:53

yashkumar18's gravatar image

5★yashkumar18
82661224


why int arr[100] ?

I can see you are solving Turbo sort.

link

answered 05 Oct '14, 19:21

betlista's gravatar image

3★betlista ♦♦
16.9k49115225
accept rate: 11%

edited 05 Oct '14, 19:22

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??

(05 Oct '14, 19:38) rahul62721★
1

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...

(05 Oct '14, 20:03) betlista ♦♦3★

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

link

answered 06 Oct '14, 11:10

rahul6272's gravatar image

1★rahul6272
11
accept rate: 0%

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

(06 Oct '14, 11:23) neo1tech9_76★

Even that might give a TLE. Try counting sort.

(06 Oct '14, 22:57) chefkaushik942★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,470
×249

question asked: 05 Oct '14, 19:15

question was seen: 957 times

last updated: 06 Oct '14, 23:53