C# Online Compiler
Example: Arithmetic Operators in C# using Functions
C
C++
C#
Java
Python
PHP
main.cs
STDIN
Run
// Arithmetic Operators in C# using Functions using System; public class W3CW { // Function to make an Addition public static int Add(int a, int b) { return a + b; } // Function to make Subtraction public static int Sub(int a, int b) { return a - b; } // Function to make Multiplication public static int Mul(int a, int b) { return a * b; } // Function to make Division public static float Div(int a, int b) { return (float)(a / b); } // Function to make Modulus public static int Mod(int a, int b) { return a % b; } // It's the driver function static public void Main (string[] args) { Console.WriteLine("Enter any two positive integer numbers:\n"); int p = Convert.ToInt32(Console.ReadLine()); int q = Convert.ToInt32(Console.ReadLine()); // It will print the final output Console.WriteLine("Addition of "+p+" + "+q+" = "+Add(p,q)); Console.WriteLine("Subtraction of "+p+" - "+q+" = "+Sub(p,q)); Console.WriteLine("Multiplication of "+p+" * "+q+" = "+Mul(p,q)); Console.WriteLine("Division of "+p+" / "+q+" = "+Div(p,q)); Console.WriteLine("Modulus of "+p+" % "+q+" = "+Mod(p,q)); } }
9 6
Output
Clear
ADVERTISEMENTS