w3resource

C#: Check if an integer is in the range -10 to 10


Check Integer in Range -10 to 10

Write a C# program to check if an integer (from the two given integers) is in the range -10 to 10.

C# Sharp Exercises: Check if an integer is in the range -10 to 10

Sample Solution:-

C# Sharp Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class Exercise36 {
    static void Main(string[] args) {
        // Prompt the user to input the first number
        Console.Write("Input a first number: ");

        // Read user input and convert it to an integer 'm'
        int m = Convert.ToInt32(Console.ReadLine());

        // Prompt the user to input the second number
        Console.Write("Input a second number: ");

        // Read user input and convert it to an integer 'n'
        int n = Convert.ToInt32(Console.ReadLine());

        // Check if either the first number 'm' or the second number 'n' is within the range -10 to 10 (inclusive)
        // Print the result of the logical OR operation between the conditions
        Console.WriteLine(((m >= -10 && m <= 10)) || ((n >= -10 && n <= 10)));
    }
}

Sample Output:

Input a first number: -5                                               
Input a second number: 8                                               
True

Flowchart:

Flowchart: C# Sharp Exercises - Check if an integer is in the range -10 to 10

For more Practice: Solve these Related Problems:

  • Write a C# program to check if both integers are in the range -10 to 10.
  • Write a C# program to find all integers in a list that fall within the -10 to 10 range.
  • Write a C# program to count how many values from a user-entered list are in the range -10 to 10.
  • Write a C# program to check if the average of two numbers lies in the -10 to 10 range.

Go to:


PREV : Check Numbers Less than 100 & Greater than 200.
NEXT : Remove 'HP' from String.

C# Sharp Code Editor:



What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.