Tsallaka zuwa abun ciki
Justice Tech School

Math and Random Numbers

<cmath> has sqrt, pow, abs, floor, ceil and round. <random> provides engines and distributions that replace rand.

Example
#include <random>
cout << sqrt(81) << " " << pow(2, 10) << " " << floor(7.9) << " " << abs(-5) << "\n";
mt19937 gen(42);
uniform_int_distribution<int> die(1, 6);
int r = die(gen);
cout << (r >= 1 && r <= 6) << "\n";

Result

9 1024 7 5
1

Exercise

Power function.

(2, 10)

Quiz Test

Which header gives sqrt?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.