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:
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 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.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework