×

# SUMTRIAN C code runtime error

 3 @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 answered 16 Mar '13, 21:19 3★ajay154 1.6k●7●20●44 accept rate: 8% @ajay154 thanks, a lot.. (17 Mar '13, 19:18) ur welcome.. (18 Mar '13, 02:05) ajay1543★
 1 @ajay154.. hi... 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 198●10●25●35 accept rate: 0%
 1 @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 3★ajay154 1.6k●7●20●44 accept rate: 8% 1 thank u very very much.. :) (19 Mar '13, 21:10) ur welcum :) (19 Mar '13, 23:33) ajay1543★
 1 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? answered 19 Mar '13, 23:12 4★srinu634 76●1●4●9 accept rate: 0% @srinu634 thanks a lot... (19 Mar '13, 23:49)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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,583
×1,461
×516
×243

question asked: 16 Mar '13, 16:15

question was seen: 1,211 times

last updated: 19 Mar '13, 23:49