Hi,
in c++ following code produces output as 1 how if i am using d as double?
double d=9/7;
cout<<"\n"<<d;
when i changed d=9/7 to d=9.0/7.0 it showed correct answer with all decimals..
Is it a rule that for using double we have to assign it a value that has a decimal otherwise it would consider it as an int?
Thanks.
in c++ following code produces output as 1 how if i am using d as double?
double d=9/7;
cout<<"\n"<<d;
when i changed d=9/7 to d=9.0/7.0 it showed correct answer with all decimals..
Is it a rule that for using double we have to assign it a value that has a decimal otherwise it would consider it as an int?
Thanks.
Comment