C# Sharp Exercises: Compute the sum of two given integers, if two values are equal then return the triple of their sum
C# Sharp Basic: Exercise-19 with Solution
Write a C# program to compute the sum of two given integers, if two values are equal then return the triple of their sum.
Sample Solution:
C# Sharp Code:
using System;
using System.Collections.Generic;
public class Exercise19 {
static void Main(string[] args)
{
Console.WriteLine(SumTriple(2,2));
Console.WriteLine(SumTriple(12,10));
Console.WriteLine(SumTriple(-5,2));
}
public static int SumTriple(int a, int b)
{
return a == b ? (a + b)*3 : a + b;
}
}
Sample Output:
12 22 -3
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# program to check two given integers and return true if one is negative and one is positive.
Next: 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.
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