Requirements
- You'll create a program to add 1 plus 2 times 3.
- Do addition first or multiplication first.
- In basic math rules, multiplication and division have higher priority than addition or subtraction.
- It is the same in programming as in mathematics.
- To add 1 to 2 and then multiply by 3, use parentheses around the 1 and 2.
Hint
Use Console.WriteLine(); to output result
Demo
using System;
class Program//from w w w . ja va 2s. c om
{
static void Main(string[] args)
{
// Multiplication has greater priority
Console.WriteLine(1 + 2 * 3);
// Forcing priority using parentheses
Console.WriteLine((1 + 2) * 3);
}
}
Result