rand() and RAND_MAX giving different values depending upon the datatype : <p>Here when I print the value of x its giving zero as output.Whereas when I print y, I am getting correct value(a random number between 0 and 1),the typecasting is the problem it seems.Why do i need to typecast it? </p>

<pre><code>double x,y;
x=rand()/RAND_MAX;
printf("X=%f\n",x);
y=(double)rand()/RAND_MAX;
printf("Y=%f",y);
</code></pre>

<p>Output</p>

<pre><code>X=0.000000
Y=0.546745
</code></pre>
