Q:

Write a C# Sharp program to find the larger from two given integers. However if the two integers have the same remainder when divided by 7, then the return the smaller integer. If the two integers are the same, return 0

0

Write a C# Sharp program to find the larger from two given integers. However if the two integers have the same remainder when divided by 7, then the return the smaller integer. If the two integers are the same, return 0

Sample Output:

21
20
10
0

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));
      Console.WriteLine(test(11, 20));
      Console.WriteLine(test(24, 10));
      Console.WriteLine(test(10, 10));
      Console.ReadLine();
    }
    public static int test(int x, int y) {
      if (x == y) return 0;
      if (x % 7 == y % 7) return (x < y) ? x: y;
      return (x > y) ? x: y;
    }
  }
}

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