Advertisement
sylviapsh

Product Sign Of 3 Numbers Without Calculation

Dec 28th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. class ProductSignOf3NumsWithoutCalculation
  3. {
  4.   static void Main()
  5.   {
  6. //Telerik Academy
  7.     //Write a program that shows the sign (+ or -) of the product of three real numbers without calculating it. Use a sequence of if statements.
  8.  
  9.     Console.Write("Please enter the first number:");
  10.     decimal firstNum = decimal.Parse(Console.ReadLine());
  11.     Console.Write("Please enter the second number:");
  12.     decimal secondNum = decimal.Parse(Console.ReadLine());
  13.     Console.Write("Please enter the third number:");
  14.     decimal thirdNum = decimal.Parse(Console.ReadLine());
  15.  
  16.     if (firstNum == 0 || secondNum == 0 || thirdNum == 0)
  17.     {
  18.       Console.WriteLine("At least one of the entered numbers is zero so the product of the numbers will be 0!");
  19.     }
  20.     else if ((firstNum > 0 && secondNum > 0 && thirdNum > 0) || (firstNum > 0 && secondNum < 0 && thirdNum < 0) || (firstNum < 0 && secondNum < 0 && thirdNum > 0) || (firstNum < 0 && secondNum >0 && thirdNum < 0))
  21.     {
  22.       Console.WriteLine("The sign of the product of the three numbers: ({0}) * ({1}) * ({2}) is PLUS (+)!", firstNum, secondNum, thirdNum);
  23.     }
  24.     else
  25.     {
  26.       Console.WriteLine("The sign of the product of the three numbers: ({0}) * ({1}) * ({2}) is MINUS (-)!", firstNum, secondNum, thirdNum);
  27.     }
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement