Re: [NETWORK 30097] Problem in C

6 views
Skip to first unread message
Message has been deleted

Pradyumn Nand

unread,
Feb 3, 2011, 10:06:14 PM2/3/11
to msitnet...@googlegroups.com
buddy

you have highlighted a very important glitch in C that is it does not do float computation when both the variables/ const/ numbers are integers.... in 1/2 1 is an integer , 2is an integer, so 1/2 will be an integer computation.... typecasting won't help because the final result of 1/2 which is zero here  due to integer computation, will be typecasted into a float....which is again 0.0000..

try writing 1.0/2 or 1/2.0 or 1.0/2.0   to get the correct answer.....

dunno but i think you have a C++ "hangover"... :)    try and get rid of it ASAP... C is a much more strict language.

AND I REQUEST ALL PEOPLE THAT  whenever you post your programming doubt please paste the code you have written like dhr00v did... makes it much more easier to run....


karan vohra

unread,
Feb 3, 2011, 10:46:03 PM2/3/11
to msitnet...@googlegroups.com
So pradyuumn .. the correct way is 1.0/2.0 .? did u try it urself ?




--
-----------------------------------------------------------------------------------------------------
You received this message because you are subscribed to the Google
Groups "NETWORK 300" group.
-----------------------------------------------------------------------------------------------------
To post to this group, send email to msitcs...@googlegroups.com
-----------------------------------------------------------------------------------------------------
To unsubscribe from this group, send email to
msitcseit201...@googlegroups.com
-----------------------------------------------------------------------------------------------------
For more options, visit this group at
http://groups.google.co.in/group/msitcseit2010?hl=en-GB
-----------------------------------------------------------------------------------------------------

Hitesh Chopra

unread,
Feb 3, 2011, 11:19:04 PM2/3/11
to msitnet...@googlegroups.com
either try 1.0/2 or 1/2.0 or 1.0/2.0
all of these will give u the float result i.e. 0.5

sahil anand

unread,
Feb 4, 2011, 9:15:40 AM2/4/11
to msitnet...@googlegroups.com
actually as pradyumn said c is a strict language it asumes that if there is a float variable i will get direct value of float only
but in same senerio if u would have taken an "x"instead of direct value
and entered value by user at run time you would not write 1.0/2
you wold enter 1/2
and it will work ...
Message has been deleted

Pradyumn Nand

unread,
Feb 5, 2011, 8:25:56 AM2/5/11
to msitnet...@googlegroups.com
hey! go easy buddy... i didn't mean to insult you or something.... and i am not a pro at this language either .... it's just that when i started learning this language, i faced similar probs, so it was actually a genuine friendly advice  :) .... and yes it helps in comparing languages.. mistakes is how we learn... although in coming two years we are going to study so many languages that it'll be hard to remember differences and syntax...

so PEACE OUT !!

Dhruv Chatterjee

unread,
Feb 6, 2011, 12:03:56 AM2/6/11
to msitnet...@googlegroups.com
Hey,Hey..It is you and not me who is taking this thing seriously..I didn't feel let down or something. I am grateful that you let me know that these kinds of hangovers are not good. And I was just saying lightly that the statement would but give the same results in C++..
 
Chill man.. We are friends and not business partners that we need to take things so seriously.. :)  

On Sat, Feb 5, 2011 at 6:55 PM, Pradyumn Nand <pradyu...@gmail.com> wrote:
hey! go easy buddy... i didn't mean to insult you or something.... and i am not a pro at this language either .... it's just that when i started learning this language, i faced similar probs, so it was actually a genuine friendly advice  :) .... and yes it helps in comparing languages.. mistakes is how we learn... although in coming two years we are going to study so many languages that it'll be hard to remember differences and syntax...

so PEACE OUT !!

--
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages