1+ using System ;
2+
3+ namespace operators
4+ {
5+ public static class DivisionExamples
6+ {
7+ public static void Examples ( )
8+ {
9+ IntegerDivision ( ) ;
10+ IntegerAsFloatingPointDivision ( ) ;
11+ FloatingPointDivision ( ) ;
12+ DivisionAssignment ( ) ;
13+ }
14+
15+ private static void IntegerDivision ( )
16+ {
17+ // <SnippetInteger>
18+ Console . WriteLine ( 13 / 5 ) ; // output: 2
19+ Console . WriteLine ( - 13 / 5 ) ; // output: -2
20+ Console . WriteLine ( 13 / - 5 ) ; // output: -2
21+ Console . WriteLine ( - 13 / - 5 ) ; // output: 2
22+ // </SnippetInteger>
23+ }
24+
25+ private static void IntegerAsFloatingPointDivision ( )
26+ {
27+ // <SnippetIntegerAsFloatingPoint>
28+ Console . WriteLine ( 13 / 5.0 ) ; // output: 2.6
29+
30+ int a = 13 ;
31+ int b = 5 ;
32+ Console . WriteLine ( ( double ) a / b ) ; // output: 2.6
33+ // </SnippetIntegerAsFloatingPoint>
34+ }
35+
36+ private static void FloatingPointDivision ( )
37+ {
38+ // <SnippetFloatingPoint>
39+ Console . WriteLine ( 16.8f / 4.1f ) ;
40+ Console . WriteLine ( 16.8d / 4.1d ) ;
41+ Console . WriteLine ( 16.8m / 4.1m ) ;
42+ // Output:
43+ // 4.097561
44+ // 4.09756097560976
45+ // 4.0975609756097560975609756098
46+ // </SnippetFloatingPoint>
47+ }
48+
49+ private static void DivisionAssignment ( )
50+ {
51+ // <SnippetDivisionAssignment>
52+ int a = 4 ;
53+ int b = 5 ;
54+ a /= b ;
55+ Console . WriteLine ( a ) ; // output: 0
56+
57+ double x = 4 ;
58+ double y = 5 ;
59+ x /= y ;
60+ Console . WriteLine ( x ) ; // output: 0.8
61+ // </SnippetDivisionAssignment>
62+ }
63+ }
64+ }
0 commit comments