C# Online Compiler
Example: Arithmetic Operators in C# using Switch Case
C
C++
C#
Java
Python
PHP
main.cs
STDIN
Run
// Arithmetic Operators in C# using Switch Case using System; public class W3CW { // 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 suggest choosing an option to make the operation Console.WriteLine("Input your choice to make an operation\n"); Console.WriteLine("1 :: for Addition"); Console.WriteLine("2 :: for Subtraction"); Console.WriteLine("3 :: for Multiplication"); Console.WriteLine("4 :: for Division"); Console.WriteLine("5 :: for Modulus"); Console.WriteLine("\nEnter your choice:\n"); int choice = Convert.ToInt32(Console.ReadLine()); // It will perform all arithmetic operations // According to user's choice & print the final output switch (choice) { case 1: Console.WriteLine("Addition of "+p+" + "+q+" = "+(p + q)); break; case 2: Console.WriteLine("Subtraction of "+p+" - "+q+" = "+(p - q)); break; case 3: Console.WriteLine("Multiplication of "+p+" * "+q+" = "+(p * q)); break; case 4: Console.WriteLine("Division of "+p+" / "+q+" = "+(float)(p + q)); break; case 5: Console.WriteLine("Modulus of "+p+" % "+q+" = "+(p % q)); break; default: Console.WriteLine("Kindly input correct choice!"); break; } } }
9 6 2
Output
Clear
ADVERTISEMENTS