Question

Write the functions to add, subtract, multiply and divide two doubles. The function returns the result...

Write the functions to add, subtract, multiply and divide two doubles. The function returns the result on the operation. Write a program to test your functions. In visual studios console application C#.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
using System;
using System.Security.AccessControl;

public class MathOperations
{
    public static double add(double n1, double n2)
    {
        return n1 + n2;
    }
    
    public static double subtract(double n1, double n2)
    {
        return n1 - n2;
    }
    
    public static double multiply(double n1, double n2)
    {
        return n1 * n2;
    }
    
    public static double divide(double n1, double n2)
    {
        return n1 / n2;
    }
    
    public static void Main(string[] args)
    {
        double n1, n2;
        Console.Write("Enter first number: ");
        n1 = Convert.ToDouble(Console.ReadLine());
        Console.Write("Enter second number: ");
        n2 = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine(n1 + " + " + n2 + " = " + add(n1, n2));
        Console.WriteLine(n1 + " - " + n2 + " = " + subtract(n1, n2));
        Console.WriteLine(n1 + " * " + n2 + " = " + multiply(n1, n2));
        Console.WriteLine(n1 + " / " + n2 + " = " + divide(n1, n2));
    }
}

Add a comment
Know the answer?
Add Answer to:
Write the functions to add, subtract, multiply and divide two doubles. The function returns the result...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT