Answer to Question #291822 in C# for Jay

Question #291822

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.




1
Expert's answer
2022-01-29T02:43:35-0500


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();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS