#include<iostream>
usingnamespace std;
int main()
{
int n;
double z;
cin>> z;
cout <<z <<"...."<< (1/z);
cout <<"\n";
n =1/z;
cout<<"n is "<<n<<"\n";
n=1/.1;
cout<<"n is "<<n<<"\n";
}
INPUT = .1 ;
OUTPUT : 0.1....10
n is 9
n is 10
if I am not wrong .1 is stored in temporary memory as a double constant , so whats the difference between the two statements , why is output different in the two cases... Plzz Help...
There shouldn't be anything wrong with your code.. I don't see any reason for the outputs to be different.
Neither does my computer. my output looks like this:
Though I'm getting the proper output, my compiler does give me a warning: "Conversion from int to double, possible loss of data" or something.
Maybe that has more of an effect with G++ than it does Visual Studio?
Try making 'n' a double.