got it guys got it thX a lot....veeeeee
got it guys got it thX a lot....veeeeee
So, instead of using --b and b++, I replace them with the value that IS correct for b in each place (assuming we think that 17 _IS_ the correct answer here - since the original expression is technically undefined, there is no "right" or "wrong" answer to that expression - it can be -46, 4118923791231, 17, 14, 19 or some other value with b = 3 to start with).Code:a = 2*b + (b-1) + 3*(b-1) +b
Then we use normal algebra rules to simplify the expression, soÖ
2 * b + (b -1) can be made into 3 * b - 1.
3 * (b - 1) + b can be made into 4 *b - 3
3 * b - 1 + 4 * b - 3 can be simplified into 7 *b - 4.
Does that make more sense to you. And by the way (appologies if you suffer from some injury or such that), but could you perhaps try to write complete words, correctly spelled (as best as you can) - it is fairly hard for someone who uses English in daily life to read "ne1" as "anyone", etc, and I don't think the people who don't even use english daily will have an EASIER task with it. It makes you look lazy and ill educated - which may be true, but if so, perhaps you can try to hide it when you are posting here
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks a lot matsp
you are genious....!!
i ll check on different cases hope it ll work true in all cases
As i m new to this so
One day i ll surely fly
please tell me for this expresion :
a = (b++) + (- - b) + (b - -) + b
here b = 4
tell me manually ans : i am getting 15
by applying your logic i am gettin 17
plz check.....!!
Last edited by ajayd; 02-06-2008 at 09:50 AM.
hk_mp5kpdw already answered you in the first reply: it is undefined behaviour. You could get 15, you could get 17, or you could get your computer blown up.
EDIT:
Though I am assuming that you actually fix the statement to become:
or at least:Code:a = (b++) + (--b) + (b--) + b;
Code:a = (b++) + (- - b) + (b--) + b;
Last edited by laserlight; 02-06-2008 at 09:51 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
plz check this is a different case in 1st case only decrement operators were used in this case both decrement as well as increment operators are used
if the given expression is itself in that form and asked to program on it then how to convert it
if i convert it using algebra i am getting different answers compared to the manual answers so