w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: Check the sum of the two given integers and return true if one of the integer is 20 or if their sum is 20

C# Sharp Basic: Exercise-21 with Solution

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.

C# Sharp Exercises: Check the sum of the two given integers and return true if one of the integer is 20 or if their sum is 20

Sample Solution:-

C# Sharp Code:

using System;
using System.Collections.Generic;

public class Exercise21 {
  static void Main(string[] args)
        {
         int x, y;
         int result;  
   
         Console.WriteLine("\nInput an integer:");  
         x = Convert.ToInt32(Console.ReadLine());
         Console.WriteLine("Input another integer:");  
         y = Convert.ToInt32(Console.ReadLine()); 
         Console.WriteLine(x == 20 || y == 20 || (x + y == 20));
    }
}

Sample Output:

Input an integer:                                                      
25                                                                     
Input another integer:                                                 
20                                                                     
True

Flowchart:

Flowchart: C# Sharp Exercises - Check the sum of the two given integers and return true if one of the integer is 20 or if their sum is 20

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# program to get the absolute value of the difference between two given numbers. Return double the absolute value of the difference if the first number is greater than second number.
Next: Write a C# program to check if an given integer is within 20 of 100 or 200.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming