operators/motivation/a.cs - Comparison of operator notation and function notation. | Lecture 5 - slide 28 : 45 Program 1 |
using System; public class OperatorsOrNot { public static int With (int a, int b, int c, int m){ return (a % m + b % m + c % m) / 3; } public static int Without (int a, int b, int c, int m){ return MyInt.Quotient( MyInt.Plus( MyInt.Plus(MyInt.Remainder(a,m), MyInt.Remainder(b,m)), MyInt.Remainder(c,m)), 3); } // Without class qualification: // Quotient( // Plus( // Plus(Remainder(a,m), Remainder(b,m)), // Remainder(c,m)), // 3); // In some languages, such as Lisp. // Alternative in languages with more liberal rules for identifiers: // (/ (+ (% a m) (% b m) (% c m)) 3) public static void Main(){ Console.WriteLine(With(18,19,25, 7)); Console.WriteLine(Without(18,19,25, 7)); } }