Lesson 5
Performing Mathematical Operations
Introduction to Mathematical Operations

Hello there! Welcome back to another exciting lesson in your C# journey. So far, you've learned how to display messages, declare variables, and even perform type conversions. Today, we're going to dive into mathematical operations, a fundamental aspect of any programming language. These operations will allow us to perform calculations, make decisions, and build complex systems.

What You'll Learn

In this lesson, we will cover the basic mathematical operations in C#, such as addition, subtraction, multiplication, division, and modulus. You'll learn how to:

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division
  5. Modulus (Remainder of Division)

Here’s a sneak peek of what you'll be doing:

C#
1// Performing basic mathematical operations 2int fuelSum = 10 + 4; // Addition 3int fuelDiff = 10 - 4; // Subtraction 4int astroSnacks = 10 * 4; // Multiplication 5double journeySplit = 10.0 / 4; // Division 6double journeyRemainder = 10 % 4; // Remainder of Division (Modulus) 7 8// Printing the results 9Console.WriteLine(fuelSum); 10Console.WriteLine(fuelDiff); 11Console.WriteLine(astroSnacks); 12Console.WriteLine(journeySplit); 13Console.WriteLine(journeyRemainder);
Why It Matters

Mathematical operations are crucial in any computational task. Whether you’re calculating the fuel needed for a mission, the number of snacks required for a trip, or splitting the journey into segments, mathematical operations make it possible.

Understanding these basics sets the foundation for more complex calculations and algorithms you'll encounter later. By mastering these operations, you'll be able to handle data more effectively, solve problems more efficiently, and build more dynamic and interactive programs.

Ready to put these concepts into practice? Let's get started with the practice section and explore the power of mathematical operations in C#.

Enjoy this lesson? Now it's time to practice with Cosmo!
Practice is how you turn knowledge into actual skills.