Q:

Write a C# Sharp program that accept two integers and return true if either one is 5 or their sum or difference is 5

0

Write a C# Sharp program that accept two integers and return true if either one is 5 or their sum or difference is 5

Sample Output:

True
False
True

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Linq;
namespace exercises
{
   class Program
    {    
        static void Main(string[] args)
        {
            Console.WriteLine(test(5, 4));
            Console.WriteLine(test(4, 3));
            Console.WriteLine(test(1, 4));
            Console.ReadLine();
        }
        public static bool test(int x, int y)
        {
            return x == 5 || y == 5 || x + y == 5 || Math.Abs(x - y) == 5;
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now