Given two numbers X and Y, develop a program to determine the difference between X and Y
If X – Y is negative, Ans = X + Y;
If X – Y is zero, Ans = 2X + 2Y;
and if X – Y is positive, compute Ans = X * Y.
using System;
using System.Collections.Generic;
using System.Globalization;
namespace App
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter X: ");
int X = int.Parse(Console.ReadLine());
Console.Write("Enter Y: ");
int Y = int.Parse(Console.ReadLine());
int diffXY = X - Y;
if (diffXY < 0)
{
int Ans = X + Y;
Console.WriteLine("{0} + {1} = {2}", X, Y, Ans);
}
if (diffXY == 0)
{
int Ans = 2 * X + 2 * Y;
Console.WriteLine("2*{0} + 2*{1} = {2}", X, Y, Ans);
}
if (diffXY > 0)
{
int Ans = X * Y;
Console.WriteLine("{0} * {1} = {2}", X, Y, Ans);
}
Console.ReadLine();
}
}
}
Comments
Leave a comment