Exercise
Equivalent Operations
Objective
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.
Write Your C# Exercise
C# Exercise Example
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);
}
}
Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.
This C# exercise is perfect for learning how to interact with the user and use input data to personalize the program's output. In this case, the program will ask the user to...
This C# exercise teaches you how to handle console output using two different methods: Console.Write and formatting with {0}. In this program, the user will in...
This C# exercise helps you practice using loops and user input. In this program, the user will be asked to input a number (a digit), and the program will display a re...
This C# exercise teaches you how to perform temperature unit conversions. The program prompts the user to input a temperature in Celsius degrees and then converts it ...
This exercise is an excellent way to get started with programming in C#. In this program, you will learn how to print a message on the screen using C#. The program wi...
This exercise is a great way to practice basic arithmetic operations in C#. In this program, you will learn how to perform an addition operation between two numbers, 12 and ...