@Ashish: i too thought the same why cant we ? is there a proper explanation ?
Well Wisher said:
(Thu, Feb 10, 2011 12:55:39 AM)
Why we should add 0.5 to x :(x+.5)
We can get the answer directly.
y=(int)(x);
I hope this is enough.
In case the round off vale shold not be a min one then we can go for (x+0.5)
Because if u type the above code having x=3.99
Then the roound off value would be 3.
That is not we are looking for.
Vinoth said:
(Thu, Mar 17, 2011 12:00:36 PM)
Sravan int is different from (int).in given program is compiled in C++ compiler.
In C language we use paranthesis to a variable.
eg:y=int (x)
here x is an float variable and y is an integer variable.
In C++ we put paranthesis to data type.
Eg:y=(int) x
eg we take x=5.6
in question asked is rounding int value(y) for given float value(x) so we add 0.5 to that number.Then the final result is
1.in C language
y=int (x+0.5)
2.in C++
y=(int) (x+0.5)
the result is same in both C and C++ compilers y=6.
ALL THE BEST...
Anuj Kumar said:
(Thu, Apr 7, 2011 04:39:21 PM)
Why we should add 0.5 to x :(x+.5)
We can get the answer directly.
y=(int)(x);
I hope this is enough.
In case the round off vale shold not be a min one then we can go for (x+0.5)
Because if u type the above code having x=3.99
Then the roound off value would be 3.
Abha said:
(Sat, Aug 27, 2011 09:21:17 PM)
According to me ans should be C because type castng is done to variable and not to a constant term. Tell me whether my perception is wrong or right. ?
Rani said:
(Fri, Sep 9, 2011 06:45:12 PM)
But option (A)=4
option(B)=3
means both are correct we need only round off not say Floor or ceil
Kanta Patidar said:
(Fri, Sep 9, 2011 06:50:12 PM)
option (a)=4
option(c)=3
option(d)=3
it means tino option is right
Vamshi Krishna said:
(Fri, Nov 25, 2011 06:52:28 AM)
I think here is the question to round of x and not the y to which it is assigning so i think (int)x+0.5 is appropriate...!!!
If not can anyone give me a proper explanation???
Ganga said:
(Thu, Dec 29, 2011 06:34:33 PM)
What is return function can you explain for me?
Why it z return0 we can also put only return know!
Bhupesh said:
(Fri, Jan 20, 2012 12:19:16 AM)
if x=3.1 then y=(int)(3.1+0.5)
so out put would 4 again, the float 3.1 value should be converted to int 3 only.