Illustrates the use of the arithmetic operators


   
 
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example3_2.csc illustrates the use of
  the arithmetic operators
*/

public class Example3_2
{

  public static void Main()
  {

    // integers and arithmetic operators
    System.Console.WriteLine("10 / 3 = " + 10 / 3);
    System.Console.WriteLine("10 % 3 = " + 10 % 3);
    int intValue1 = 10;
    int intValue2 = 3;
    System.Console.WriteLine("intValue1 / intValue2 = " +
      intValue1 / intValue2);
    System.Console.WriteLine("intValue1 % intValue2 = " +
      intValue1 % intValue2);

    // floats and arithmetic operators
    System.Console.WriteLine("10f / 3f = " + 10f / 3f);
    float floatValue1 = 10f;
    float floatValue2 = 3f;
    System.Console.WriteLine("floatValue1 / floatValue2 = " +
      floatValue1 / floatValue2);

    // doubles and arithmetic operators
    System.Console.WriteLine("10d / 3d = " + 10d / 3d);
    System.Console.WriteLine("10.0 / 3.0 = " + 10.0 / 3.0);
    double doubleValue1 = 10;
    double doubleValue2 = 3;
    System.Console.WriteLine("doubleValue1 / doubleValue2 = " +
      doubleValue1 / doubleValue2);

    // decimals and arithmetic operators
    System.Console.WriteLine("10m / 3m = " + 10m / 3m);
    decimal decimalValue1 = 10;
    decimal decimalValue2 = 3;
    System.Console.WriteLine("decimalValue1 / decimalValue2 = " +
      decimalValue1 / decimalValue2);

    // multiple arithmetic operators
    System.Console.WriteLine("3 * 4 / 2 = " + 3 * 4 / 2);

  }

}