Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Basic Algorithm Exercises: Find the larger from two given integers


C# Sharp Basic Algorithm: Exercise-52 with Solution

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 return the smaller integer. If the two integers are the same, return 0.

Pictorial Presentation:

C# Sharp: Basic Algorithm Exercises - Find the larger from two given integers.

Sample Solution:-

C# Sharp Code:

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;
    }
  }
}

Sample Output:

21
20
10
0

Flowchart:

C# Sharp: Flowchart: Find the larger from two given integers.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: 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.
Next: Write a C# Sharp program to check two given integers, each in the range 10..99. Return true if a digit appears in both numbers, such as the 3 in 13 and 33

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.