Computer Club MNNIT
Would you like to react to this message? Create an account in a few clicks or log in to continue.

STAR - Another one

4 posters

Go down

STAR - Another one Empty STAR - Another one

Post  SwitchCase Wed Aug 13, 2008 10:11 am

This is a snippet

for(double r=0.0;r!=1.0;r+=0.1)printf("*");



How many * will be printed.
And Why???

SwitchCase

Posts : 5
Join date : 2008-08-13

Back to top Go down

STAR - Another one Empty Re: STAR - Another one

Post  Rahul Agrawal Wed Aug 13, 2008 11:11 am

check out this......
u will understand....

float a=3.4;
float b=3.5;
if(a==3.4)
cout<<"hi1";
else
cout<<"bye1";
if(b==3.5)
cout<<"hi2";
else
cout<<"bye2";

Rahul Agrawal

Posts : 3
Join date : 2008-08-13

Back to top Go down

STAR - Another one Empty Re: STAR - Another one

Post  Rahul Agrawal Wed Aug 13, 2008 11:12 am

ohh..ans of ur que is infinite..........

Rahul Agrawal

Posts : 3
Join date : 2008-08-13

Back to top Go down

STAR - Another one Empty @rahul

Post  mnnit.rahul Wed Aug 13, 2008 11:27 am

infinite to hai but kyu???
are hum use 0.1 time increase kr rahe hai usme kuch panga hai
because even after becoming 1 r !=1.0 but if we increase r by 1 then it works fine

mnnit.rahul

Posts : 16
Join date : 2008-08-10

Back to top Go down

STAR - Another one Empty Re: STAR - Another one

Post  shivang Wed Aug 13, 2008 1:20 pm

Floating-point decimal values generally do not have an exact binary representation. This is a side effect of how the CPU represents floating point data. Different compilers and CPU architectures store temporary results at different precisions, so results will differ depending on the details of your environment. If you do a calculation and then compare the results against some expected value it is highly unlikely that you will get exactly the result you intended.
shivang
shivang

Posts : 22
Join date : 2008-08-11
Age : 35
Location : Tondon 174

Back to top Go down

STAR - Another one Empty @shivang

Post  mnnit.rahul Thu Aug 14, 2008 2:13 am

if this is the case the
double t=1.0
if(t==1.0)
cout<<"yes";
else
cout<<"no";
this should gi\ve the answer NO
but instead it i giving YES
moreover if we increase the duoblevalue by 1 it works fine but problem came when we increase it by 0.1

mnnit.rahul

Posts : 16
Join date : 2008-08-10

Back to top Go down

STAR - Another one Empty Re: STAR - Another one

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum