Illustrates the use of the arithmetic operators : Operators « Language Basics « C# / C Sharp






Illustrates the use of the arithmetic operators

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);

  }

}

           
         
  








Related examples in the same category

1.The + Operator Is Left Associative
2.Math Operators with int value
3.Demonstrate the difference between prefix postfix forms of ++Demonstrate the difference between prefix 
   postfix forms of ++
4.Demonstrate the relational and logical operatorsDemonstrate the relational and logical operators
5.Demonstrate the short-circuit operatorsDemonstrate the short-circuit operators
6.Side-effects can be importantSide-effects can be important
7.Prevent a division by zero using the ? 1Prevent a division by zero using the ? 1
8.Self incrementSelf increment
9.Self decreaseSelf decrease
10.Illustrates the use of the comparison operatorsIllustrates the use of the comparison operators
11.Illustrates the use of the Boolean logical operatorsIllustrates the use of the Boolean logical operators
12.Ternary operatorTernary operator
13.Illustrates the use of the ternary operatorIllustrates the use of the ternary operator
14.Illustrates the use of the bitwise operatorsIllustrates the use of the bitwise operators
15.Illustrates the use of the shortcut operatorsIllustrates the use of the shortcut operators
16.Prefix and postfix versions of the increment and decrement operatorsPrefix and postfix versions of the increment and decrement operators
17.Operator precedenceOperator precedence
18.Demonstrates compound assignment operatorsDemonstrates compound assignment operators
19.Relational Operators 3
20.Numeric Operators 3
21.Numeric Operators 1
22.Relational Operators
23.control the operator evaluation sequence
24.'logical and' and bitwise and
25.logical or and bitwise or
26.And Assignment
27.Or Assignment
28.Iff operator in C#
29.logical exclusive-or
30.Conditional operator and Math calculation
31.Add Assigment for both number and string value