Menu
Coddy logo textTech

Arithmetic Operators

Part of the Fundamentals section of Coddy's C# journey — lesson 15 of 69.

Operators are used to perform operations on values.

First we will discuss the most basic arithmetic operators, they may be familiar from math classes.

OperatorOperationExample
+Addition3 + 2 = 5
-Subtraction3 - 2 = 1
*Multiplication3 * 2 = 6
/Division4 / 2 = 2

Let's see usage example,

int a = 3;
int b = 5;
int c = a + b; // c holds 8

When working with decimal numbers in C#, we use the double data type, which can store numbers with decimal points.

The same arithmetic operators (+, -, *, /) work with doubles just like they do with integers:

double x = 3.3;
double y = 4.1;
double z = x + y; // z holds 7.4
challenge icon

Challenge

Beginner

Write a code that initializes two variables, a and b, with the values 5.2 and 2.6 (respectively).

After that, initialize another variable c that will hold the result of a / b.

Cheat sheet

Arithmetic operators perform mathematical operations on values:

OperatorOperationExample
+Addition3 + 2 = 5
-Subtraction3 - 2 = 1
*Multiplication3 * 2 = 6
/Division4 / 2 = 2

Using arithmetic operators with integers:

int a = 3;
int b = 5;
int c = a + b; // c holds 8

Using arithmetic operators with decimal numbers (double):

double x = 3.3;
double y = 4.1;
double z = x + y; // z holds 7.4

Try it yourself

using System;

public class Program {
    public static void Main(string[] args) {
        // Type your code below
        
        
        // Don't change the line below
        Console.WriteLine("a = " + a + ", b = " + b + ", c = " + c);
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals