﻿ C# - 2 integers, check one of them is 30 or their sum is 30

# C#: Check two given integers, and return true if one of them is 30 or if their sum is 30

## C# Sharp Basic Algorithm: Exercise-3 with Solution

Write a C# Sharp program to check two given integers, and return true if one of them is 30 or if their sum is 30.

Visual Presentation:

Sample Solution:

C# Sharp Code:

``````using System;

// Namespace declaration
namespace exercises
{
// Class declaration
class Program
{
// Main method - entry point of the program
static void Main(string[] args)
{
// Calling the 'test' method and displaying the returned boolean values
Console.WriteLine(test(30, 0));    // Output: True
Console.WriteLine(test(25, 5));    // Output: True
Console.WriteLine(test(20, 30));   // Output: True
Console.WriteLine(test(20, 25));   // Output: False
Console.ReadLine();                // Keeping the console window open
}

// Method to check conditions based on two integer parameters x and y
public static bool test(int x, int y)
{
// Returning true if any of the conditions are met:
// 1. x equals 30
// 2. y equals 30
// 3. The sum of x and y equals 30
return x == 30 || y == 30 || (x + y == 30);
}
}
}
```
```

Sample Output:

```True
True
True
False```

Flowchart:

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿