codegurukool.com · Free coding tutorials & online compiler

Home › C++ Tutorial › C++ math

C++ math

cmath functions.

Include cmath for sqrt, pow, round, ceil, floor, abs. max and min need no header.

Example code

#include <iostream>
#include <cmath>
using namespace std;
int main() {
  cout << sqrt(64) << " " << pow(2, 10) << " " << round(2.6) << " " << max(3, 8) << endl;
  return 0;
}

Run this code in the online editor

← C++ stringsC++ if...else and switch →