Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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?

Test your Programming skills with w3resource's quiz.