Q:

Write a C# Sharp program to check three given integers and return true if one of them is 20 or more less than one of the others

0

Write a C# Sharp program to check three given integers and return true if one of them is 20 or more less than one of the others

Sample Output:

True
True
False

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(11, 21, 31));
            Console.WriteLine(test(11, 22, 31));
            Console.WriteLine(test(10, 20, 15));
            Console.ReadLine();
        }
        public static bool test(int x, int y, int z)
        {
          return Math.Abs(x - y) >= 20 || Math.Abs(x - z) >= 20 ||
                   Math.Abs(y - z) >= 20;
        }
    }
}

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