Your summation function makes no sense. You pass in a parameter which is ignored and then do some fairly random calculations, and return the value which will be zero, after a single iteration of the loop.
Well the first thing you need to do is to define what the summation function is supposed to do; I cannot make any sense out of it. Once you have done that, then define the steps required and convert them to code. It would probably help you immensely to use meaningful names for your variables rather than single letters which make it difficult to understand.
ya it is thank fren i got it...matter was with the printf statement i gav at second loop ,wen i pass the printf statement inside the 1st loop itself n removing the second for loop as condition where same ...den i got the exact answer..
What are you doing?
OK, you are trying to implement the "Kahan summation algorithm"[^].
However you have to read carefully and understand it, before actually coding.
For instance, as shown by the algorithm pseudo-code[^], the parameter to the summation function must be an array, while you are using a float.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
i tried using array but seem it not working can u please help me out with code making modification...actual thing what i want is to do the summation of all the generated random number which is store at b.
Except for a rather small subset of numbers, calculations with computers involving floating-point numbers are approximate.
Integer arithmetic doesn't suffer from this pitfall.
However, if you are talking about the result of the code I posted - then consider reviewing the printf statements - in each of them I have used the %.2f format specifier to tell printf to only print 2 digits after the decimal place. The point is - the answer is as close to exact as floats will give you, it is only the display that is (grossly) approximate.
You can get a less approximate result printed if you change the print specifiers to %f
CPallini i have given just for 5 number as demo but in real my count is above 60000 ?and i am searching for the summation for all the 60000+ value which give correct result.it wouldt be possible for what?
Seems like a reasonable assumption to me. I'd seen your mention of it earlier, but hadn't seen a confirmation of this so guessed (wrongly?) where the problem lay.
Thanks for the impetus to re-investigate the method - I seem to remember using it for something a while back, but brain-rot defeats me..
Last Visit: 31-Dec-99 18:00 Last Update: 31-Jul-14 3:53