Check out example codes for "Mod in c++". It will help you in understanding the concepts better.

Code Example 1

``````if (iNum % 2 == 0)
{
cout << num << " is even ";
}
// % is used to mod numbers``````

Code Example 2

``````#include <iostream>
using namespace std;

int main() {
cout << 11%3; // Prints 2
}``````

Code Example 3

``````#include <bits/stdc++.h>
using namespace std;

int main() {
int MOD = 1e9+7; //MOD = 1000000007
int a = 1224839897; //let a be a large number
int b = 1343589784; //also b is a large number
//then if we perform multiplication, addition or subtraction
//between these integers then they might result to overflow
//to overcome this situation we use modulo with a prime number > 1billion
//alright lets perform those operations...

//MULTIPLICATION
int mul = (a*b) % MOD;
//ADDITION AND SUBTRACTION IS QUITE A TRICKY OPERATION WITH MODULO
//which goes like this...
int add = (a % MOD + b % MOD) % MOD;
int sub = (a % MOD - b % MOD + MOD) % MOD;

cout << "Multiplication : " << mul << '\n';