Exercise
Two negative numbers
Objetive
Write a C# program to prompt the user for two numbers and determine if both numbers are negative or not.
Example Code
using System; // Importing the System namespace to use Console functionalities
class Program
{
// Main method where the program execution begins
static void Main()
{
// Declaring two variables to store the numbers entered by the user
int number1, number2;
// Asking the user to enter the first number
Console.Write("Enter the first number: ");
number1 = Convert.ToInt32(Console.ReadLine()); // Converting the input to an integer
// Asking the user to enter the second number
Console.Write("Enter the second number: ");
number2 = Convert.ToInt32(Console.ReadLine()); // Converting the input to an integer
// Checking if both numbers are negative
if (number1 < 0 && number2 < 0) // If both numbers are less than 0
{
// Displaying a message if both numbers are negative
Console.WriteLine("Both numbers are negative."); // Informing the user that both numbers are negative
}
else
{
// Displaying a message if one or both numbers are not negative
Console.WriteLine("Both numbers are not negative."); // Informing the user that one or both numbers are not negative
}
}
}