w3resource
C# Sharp Programming Exercises

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.

C# Sharp Exercises: 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:

Flowchart: C# Sharp Exercises - Compute the sum of two given integers, if two values are equal then return the triple of their sum

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?



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