Math and Booleans

 

Find Maximum and Minimum of two numbers

The max(x,y) and min(x,y) can be used to find the highest and lowest values, respectively of x and y.

 

Examples:

 

For max(x,y)

 

#include <iostream>
using namespace std;

int main() 
{
  cout << max(2, 8);
  return 0;
}

Output:

8

 

 

Example:

 

For min(x,y)

 

#include <iostream>
using namespace std;

int main() 
{
  cout << min(3, 7);
  return 0;
}

 

Output:

3

 

 

Note : In order to introduce other math functions we need to include <cmath> header file

 

sqrt() : Finds the square root of a number

round() : rounds a number

log() : Finds the logarithm of the number.

 

Example:

 

#include <iostream>
#include <cmath>

using namespace std;


int main() {
  cout << sqrt(16) << "\n";
  cout << round(4.2) << "\n";
  cout << log(2) << "\n";
  return 0;
}

 

Output:

4
4
0.69

 

Some other important functions included are sin() , cos() , tan() , exp() , pow() and many more including most trigonometric functions.

 

Boolean Expressions:

 

These give values as either yes or no, on or off, true or false.

Bool datatype as mentioned earlier gives these values.

 

#include <iostream>

using namespace std;


int main() {

  bool theSunIsHot = true;
  bool everyoneLikesmonkeys = false;
  cout << theSunIsHot << "\n";
  cout << everyoneLikesmonkeys;
  return 0;
}

 

Output :

1
0