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

×

SUMTRIAN C code runtime error

please help run this C code...

http://www.codechef.com/viewsolution/1944333

producing runtime error.... works well on my pc.. PLEASE HELP.......

asked 16 Mar '13, 16:15

hitesh091's gravatar image

3★hitesh091
198102535
accept rate: 0%


@hitesh091 your logic is right.but you have used an array b[max] where max=100 which is main cause for SIGSEGV error i.e. Segmentation fault(using array index out of limit) because number of test cases in problem is 1000 there just declare b as b[1002] for a safer side and your code will successfully run.
but what is need to write all output at a time you can output whenever your logic has been done.here you can see your code without such type of output CLICK HERE

link

answered 16 Mar '13, 21:19

ajay154's gravatar image

3★ajay154
1.6k72044
accept rate: 8%

@ajay154 thanks, a lot..

(17 Mar '13, 19:18) hitesh0913★

ur welcome..

(18 Mar '13, 02:05) ajay1543★

@ajay154..

hi...
i want to know how to print decimal numbers after 6 digits of precision in a float-double type.

link

answered 18 Mar '13, 16:56

hitesh091's gravatar image

3★hitesh091
198102535
accept rate: 0%

@hitesh ..
it is simple:
you can use double as your datatype for more than 6 digit of precision and use %[n]f as format specifier in printf.where n is number of digit after decimal you want to print .as the example shows



double y = 0.012345678910; printf ("y=%.10lf\n",y);


will output 0.0123456789. and the presion of calculation will also be more than that of float datatype.

link

answered 19 Mar '13, 01:02

ajay154's gravatar image

3★ajay154
1.6k72044
accept rate: 8%

1

thank u very very much.. :)

(19 Mar '13, 21:10) hitesh0913★

ur welcum :)

(19 Mar '13, 23:33) ajay1543★

One small tweak you can make is instead of storing results in another array, print it directly once you calculate the result.

for : i<-1 to t

   scan t
   do all the work to get the answer.// logic
   print result //instead of storing the result in an separate array. print it here itself.

ex:1-

scan the testcase:

print the answer

scan another testcase

print the answer.

and so on...... why this approach? think of the problems where answer is very large and there are many test cases. initialising another array is a waste of space right?

link

answered 19 Mar '13, 23:12

srinu634's gravatar image

4★srinu634
76149
accept rate: 0%

@srinu634 thanks a lot...

(19 Mar '13, 23:49) hitesh0913★
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:

×2,397
×1,388
×487
×228

question asked: 16 Mar '13, 16:15

question was seen: 1,175 times

last updated: 19 Mar '13, 23:49