Q:

Write a C# Sharp program to check if a given non-negative given number is a multiple of 3 or 7, but not both

0

Write a C# Sharp program to check if a given non-negative given number is a multiple of 3 or 7, but not both

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

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