Exercise
Multiple operations and precedences
Objetive
Write a C# program to print the result of the following operations:
-1 + 3 * 5
(24 + 5) % 7
15 + (-4) * 6 / 11
2 + 10 / 6 * 1 - 7 % 2
Example Code
using System; // Importing the System namespace to use Console functionalities
// Main class of the program
public class Program
{
// Main method where the program execution begins
static void Main()
{
// Calculating the result of -1 + 3 * 5
int result1 = -1 + 3 * 5;
// Printing the result of -1 + 3 * 5 to the screen
Console.WriteLine("The result of -1 + 3 * 5 is: " + result1);
// Calculating the result of (24 + 5) % 7
int result2 = (24 + 5) % 7;
// Printing the result of (24 + 5) % 7 to the screen
Console.WriteLine("The result of (24 + 5) % 7 is: " + result2);
// Calculating the result of 15 + (-4) * 6 / 11
int result3 = 15 + (-4) * 6 / 11;
// Printing the result of 15 + (-4) * 6 / 11 to the screen
Console.WriteLine("The result of 15 + (-4) * 6 / 11 is: " + result3);
// Calculating the result of 2 + 10 / 6 * 1 - 7 % 2
int result4 = 2 + 10 / 6 * 1 - 7 % 2;
// Printing the result of 2 + 10 / 6 * 1 - 7 % 2 to the screen
Console.WriteLine("The result of 2 + 10 / 6 * 1 - 7 % 2 is: " + result4);
}
}