Wednesday, January 22, 2014

DoubleVariable.cs

using System;

class DoubleVariable
    {
        static void Main(string[] args)
        {
            int i;
            double d;
            i = 100 / 3;
            d = 100 / 3;  
            Console.WriteLine("i is {0}",i);
            Console.WriteLine("d is {0}",d);
            d = 100 / 3.0;
            Console.WriteLine("now d is {0}", d);
        }
    }

Program Notes:
 d = 100 /3 ; stores 33 in variable 'd' since the expression int / int results in int.
when it is re-written as d = 100 / 3.0; now int / double results in double

No comments:

Post a Comment