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


SUMTRIAN C code runtime error

please help run this C code...

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

asked 16 Mar '13, 16:15

hitesh091's gravatar image

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 you can see your code without such type of output CLICK HERE


answered 16 Mar '13, 21:19

ajay154's gravatar image

accept rate: 8%

@ajay154 thanks, a lot..

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

ur welcome..

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


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


answered 18 Mar '13, 16:56

hitesh091's gravatar image

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.


answered 19 Mar '13, 01:02

ajay154's gravatar image

accept rate: 8%


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.


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?


answered 19 Mar '13, 23:12

srinu634's gravatar image

accept rate: 0%

@srinu634 thanks a lot...

(19 Mar '13, 23:49) hitesh0913★
toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 16 Mar '13, 16:15

question was seen: 1,219 times

last updated: 19 Mar '13, 23:49