C# Sharp Exercises: Check if an given integer is within 20 of 100 or 200
C# Sharp Basic: Exercise-22 with Solution
Write a C# program to check if an given integer is within 20 of 100 or 200.
Sample Solution:-
C# Sharp Code:
using System;
using System.Collections.Generic;
public class Exercise22 {
static void Main(string[] args) {
Console.WriteLine("\nInput an integer:");
int x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(result(x));
}
public static bool result(int n) {
if (Math.Abs(n - 100) <= 20 || Math.Abs(n - 200) <= 20)
return true;
return false;
}
}
Sample Output:
Input an integer: 25 False
Sample Output:
Input an integer: 50 False
Sample Output:
Input an integer: 70 False
Sample Output:
Input an integer: 80 True
Sample Output:
Input an integer: 90 True
Sample Output:
Input an integer: 110 True
Sample Output:
Input an integer: 120 True
Sample Output:
Input an integer: 125 False
Sample Output:
Input an integer: 130 False
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# program to check the sum of the two given integers and return true if one of the integer is 20 or if their sum is 20.
Next: Write a C# program to convert a given string into lowercase.
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