Not Simple Math
Let’s talk about a bit more complicated math. Sometimes we have a lot of calculations. In C++ (like in math) works the operator precedence, which means that groups of operators have higher priority (precedence) than other ones. For example, we do multiplication and division before addition and subtraction in expressions:
12int x = 4 + 3 * 3; cout << x;
The program firstly calculates 3 * 3 (multiplication) and then adds 4.
The expressions in the parentheses have higher precedence than other operators and the calculations in them must be executed first.
C++ provides us with a huge number of useful functions for math tasks. Let’s take a look at the more common ones.
The functions max(x, y)
and min(x, y)
can be used to find the highest and lowest values of x
and y
respectively:
12cout << max(9, 2) << endl; cout << min(9, 2);
Grazie per i tuoi commenti!
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Awesome!
Completion rate improved to 3.33
Not Simple Math
Scorri per mostrare il menu
Let’s talk about a bit more complicated math. Sometimes we have a lot of calculations. In C++ (like in math) works the operator precedence, which means that groups of operators have higher priority (precedence) than other ones. For example, we do multiplication and division before addition and subtraction in expressions:
12int x = 4 + 3 * 3; cout << x;
The program firstly calculates 3 * 3 (multiplication) and then adds 4.
The expressions in the parentheses have higher precedence than other operators and the calculations in them must be executed first.
C++ provides us with a huge number of useful functions for math tasks. Let’s take a look at the more common ones.
The functions max(x, y)
and min(x, y)
can be used to find the highest and lowest values of x
and y
respectively:
12cout << max(9, 2) << endl; cout << min(9, 2);
Grazie per i tuoi commenti!