Calculator in c# using Methods static method using return method
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CP_Methods_paractise
{
class Program
{
public static double addition(double num1, double num2)
{
double result = num1 + num2;
return result;
}
public static double Substraction(double num1, double num2)
{
double result = num1 - num2;
return result;
}
public static double Multiplication(double num1, double num2)
{
double result = num1 * num2;
return result;
}
public static double Devision(double num1, double num2)
{
double result = num1 / num2;
return result;
}
static void Main(string[] args)
{
Console.WriteLine("Enter First Number:");
double a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Second Number:");
double b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Operator do you want to perform(+,-,*,/)");
string op = Convert.ToString(Console.ReadLine());
if (op=="+")
{
Console.WriteLine("Addition of Numbers is:{0}",Program.addition(a,b));
}
else if (op == "-")
{
Console.WriteLine("Substraction of Numbers is:{0}",Program.Substraction(a,b));
}
else if (op == "*")
{
Console.WriteLine("Multilication of Numbers is:{0}", Program.Multiplication(a, b));
}
else if (op == "/")
{
Console.WriteLine("Devision of Numbers is:{0}", Program.Devision(a, b));
}
else
{
Console.WriteLine("Invalid Operation");
}
}
}
}
Comments
Post a Comment