Q:

Write a C# Sharp program to check if a given number is within 2 of a multiple of 10

0

Write a C# Sharp program to check if a given number is within 2 of a multiple of 10

Sample Output:

False
False
True
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(3));
            Console.WriteLine(test(7));
            Console.WriteLine(test(8));
            Console.WriteLine(test(21));
            Console.ReadLine();
        }
        public static bool test(int n)
        {
             return n % 10 <= 2 || n % 10 >= 8;
        }
    }
}

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