Math Op

Math operators in computer programming are essential tools for performing numerical calculations and manipulating data. They enable programmers to perform basic arithmetic operations such as addition, subtraction, multiplication, and division, as well as more complex mathematical operations like exponentiation, modulus, and bitwise operations. By utilizing math operators, programmers can write concise and efficient code to solve various computational problems, implement algorithms, and process data. Additionally, math operators play a crucial role in expressing logical conditions and comparisons, facilitating decision-making processes within programs.

Select Languages

Examples

C

int carCount = 6;
int truckCount = 3;

int total = carCount + truckCount;
printf("%d \n", total);

int subtract = carCount - truckCount;
printf("%d \n", subtract);

int multiple = carCount * truckCount;
printf("%d \n", multiple);

int divisible = carCount / truckCount;
printf("%d \n", divisible);

// performs division and gets remainder which is 0
int modulo = carCount % truckCount;
printf("%d \n", modulo);

C#

int carCount = 6;
int truckCount = 3;

int total = carCount + truckCount;
Console.WriteLine(total + "\n");

int subtract = carCount - truckCount;
Console.WriteLine(subtract + "\n");

int multiple = carCount * truckCount;
Console.WriteLine(multiple + "\n");

int divisible = carCount / truckCount;
Console.WriteLine(divisible + "\n");

// performs division and gets remainder which is 0
int modulo = carCount % truckCount;
Console.WriteLine(modulo + "\n");

C++

int carCount = 6;
int truckCount = 3;

int total = carCount + truckCount;
cout << total << endl;

int subtract = carCount - truckCount;
cout << subtract << endl;

int multiple = carCount * truckCount;
cout << multiple << endl;

int divisible = carCount / truckCount;
cout << divisible << endl;

// performs division and gets remainder which is 0
int modulo = carCount % truckCount;
cout << modulo << endl;

Go

var carCount = 6;
var truckCount = 3;

var total = carCount + truckCount;
fmt.Println(total);

var subtract = carCount - truckCount;
fmt.Println(subtract);

var multiple = carCount * truckCount;
fmt.Println(multiple);

var divisible = carCount / truckCount;
fmt.Println(divisible);

// performs division and gets remainder which is 0
var modulo = carCount % truckCount;
fmt.Println(modulo);

Java

int carCount = 6;
int truckCount = 3;

int total = carCount + truckCount;
System.out.println(total);

int subtract = carCount - truckCount;
System.out.println(subtract);

int multiple = carCount * truckCount;
System.out.println(multiple);
 
int divisble = carCount / truckCount;
System.out.println(divisble);
 
// performs division and gets remainder which is 0
int modulo = carCount % truckCount;
System.out.println(modulo);

JavaScript

const carCount = 6;
const truckCount = 3;

const total = carCount + truckCount;
console.log(total);

const subtract = carCount - truckCount;
console.log(subtract);

const multiple = carCount * truckCount;
console.log(multiple);

const divisible = carCount / truckCount;
console.log(divisible);

// performs division and gets remainder which is 0
const modulo = carCount % truckCount;
console.log(modulo);

Kotlin

val carCount = 6;
val truckCount = 3;

val total = carCount + truckCount;
println(total);

val subtract = carCount - truckCount;
println(subtract);

val multiple = carCount * truckCount;
println(multiple);

val divisible = carCount / truckCount;
println(divisible);

// performs division and gets remainder which is 0
val modulo = carCount % truckCount;
println(modulo);

MatLab

carCount = 6;
truckCount = 3;

total = carCount + truckCount;
disp(total);

subtract = carCount - truckCount;
disp(subtract);

multiple = carCount .* truckCount;
disp(multiple);

divisble = carCount ./ truckCount;
disp(divisble);

% performs division and gets remainder which is 0
modulo = mod(carCount, truckCount);
disp(modulo);

PHP

$carCount = 6;
$truckCount = 3;

$total = $carCount + $truckCount;
echo $total. "\n";

$subtract = $carCount - $truckCount;
echo $subtract. "\n";

$multiple = $carCount * $truckCount;
echo $multiple. "\n";

$divisible = $carCount / $truckCount;
echo $divisible, "\n";

// performs division and gets remainder which is 0
$modulo = $carCount % $truckCount;
echo $modulo. "\n";

Python

carCount = 6;
truckCount = 3;

total = carCount + truckCount;
print(total);

subtract = carCount - truckCount;
print(subtract);

multiple = carCount * truckCount;
print(multiple);

divisible = carCount / truckCount;
print(divisible);

#  performs division and gets remainder which is 0
modulo = carCount % truckCount;
print(modulo);

R

carCount <- 6;
truckCount <- 3;

total <- carCount + truckCount
print(total)

subtract <- carCount - truckCount
print(subtract)

multiple <- carCount * truckCount
print(multiple)

divisible <- carCount / truckCount
print(divisible)

#  performs division and gets remainder which is 0
modulo <- carCount %% truckCount
print(modulo)

Ruby

carCount = 6;
truckCount = 3;

total = carCount + truckCount
puts total

subtract = carCount - truckCount
puts subtract

multiple = carCount * truckCount
puts multiple

divisible = carCount / truckCount
puts divisible

#  performs division and gets remainder which is 0
modulo = carCount % truckCount
puts modulo

Rust

let carCount = 6;
let truckCount = 3;

let total = carCount + truckCount;
println!("{}", total);
    
let subtract = carCount - truckCount;
println!("{}", subtract);

let multiple = carCount * truckCount;
println!("{}", multiple);

let divisible = carCount / truckCount;
println!("{}", divisible);

// performs division and gets remainder which is 0
let modulo = carCount % truckCount;
println!("{}", modulo);

Scala

var carCount = 6;
var truckCount = 3;

var total = carCount + truckCount;
println(total);

var subtract = carCount - truckCount;
println(subtract);

var multiple = carCount * truckCount;
println(multiple);

var divisible = carCount / truckCount;
println(divisible);

// performs division and gets remainder which is 0
var modulo = carCount % truckCount;
println(modulo);

Swift

var carCount = 6;
var truckCount = 3;

var total = carCount + truckCount;
print(total);

var subtract = carCount - truckCount;
print(subtract);

var multiple = carCount * truckCount;
print(multiple);

var divisible = carCount / truckCount;
print(divisible);

// performs division and gets remainder which is 0
var modulo = carCount % truckCount;
print(modulo);

TypeScript

const carCount = 6;
const truckCount = 3;

const total: number = carCount + truckCount;
console.log(total);

const subtract: number = carCount - truckCount;
console.log(subtract);

const multiple: number = carCount * truckCount;
console.log(multiple);

const divisible: number = carCount / truckCount;
console.log(divisible);

// performs division and gets remainder which is 0
const modulo: number = carCount % truckCount;
console.log(modulo);

Copyright 2025. All Rights Reserved. IronCodeMan.