w3resource
C# Sharp Programming Exercises

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(10, 10));
            Console.ReadLine();
        }
        public static int test(int x, int y)
        {
          if (x == y)
            {
                return 0;
            }
            else if ((x % 7 == y % 7 && x < y) || x > y)
            {
                return x;
            }
            else
            {
                return y;
            }
          }
    }
}

Sample Output:

21
20
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?



New Content: Composer: Dependency manager for PHP, R Programming