C++ has the same operators as C: arithmetic + - * / % ++ --, assignment, comparison and logical operators.
<cmath> provides sqrt(), pow(), round(), ceil(), floor(), abs(); std::max() and std::min() are in <algorithm>.
Arithmetic and the cmath library.
✍️ 2 exercises in this lessonC++ has the same operators as C: arithmetic + - * / % ++ --, assignment, comparison and logical operators.
<cmath> provides sqrt(), pow(), round(), ceil(), floor(), abs(); std::max() and std::min() are in <algorithm>.
Mastering C++ Operators & Math helps you write clean and reliable C++ code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
#include <iostream>
#include <cmath>
#include <algorithm>
int main() {
std::cout << 17 / 5 << " " << 17 % 5 << " " << 17 / 5.0 << "\n";
std::cout << std::sqrt(144) << " " << std::pow(2, 8) << "\n";
std::cout << std::round(2.5) << " " << std::ceil(2.1) << "\n";
std::cout << std::max(7, 3) << "\n";
return 0;
}
3 2 3.4 12 256 3 3 7
Check what you learned in “C++ Operators & Math”.
Get 2 to the power of 8.
std::(2, 8)
Which header contains sqrt() and pow()?
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services