Exercise
Equivalent operations
Objetive
Write a C# program to ask the user for three numbers (a, b, c) and display the result of (a+b)·c and the result of a·c + b·c.
Example Code
using System; // Importing the System namespace to use Console functionalities
// Main class of the program
class Program
{
// Main method where the program execution begins
static void Main()
{
// Declaring three variables to store the numbers entered by the user
double a, b, c;
// Asking the user to enter the first number and reading the input
Console.Write("Enter the first number (a): ");
a = Convert.ToDouble(Console.ReadLine());
// Asking the user to enter the second number and reading the input
Console.Write("Enter the second number (b): ");
b = Convert.ToDouble(Console.ReadLine());
// Asking the user to enter the third number and reading the input
Console.Write("Enter the third number (c): ");
c = Convert.ToDouble(Console.ReadLine());
// Calculating the result of (a + b) * c
double result1 = (a + b) * c;
// Calculating the result of a * c + b * c
double result2 = a * c + b * c;
// Printing the results of the two operations to the screen
Console.WriteLine("The result of (a + b) * c is: {0}", result1);
Console.WriteLine("The result of a * c + b * c is: {0}", result2);
}
}