Zain Afzal

Zain Afzal

  • NA
  • 2
  • 1.4k

Unable to understand the code

Aug 31 2017 7:17 AM
I am doing some basic C# exercises to learn C# which provided the solution to the problems too however, I am unable to understand the code.
 
Problem:
Write a C# program to check if an integer is within 20 of 100 or 200.

Sample Output:
Input an integer
25
False
 
Solution:
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) <= 10 || Math.Abs(n - 200) <= 10)
      return true;
   return false;
}
}
 Can't understand the code below:
   if (Math.Abs(n - 100) <= 10 || Math.Abs(n - 200) <= 10)
      return true;
   return false;
 
I am a beginner in c# but not in overall programming 
 
 

Answers (1)