Trusted answers to developer questions

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In C++, the ** rint() function** is used to round the argument

`x`

to an integral value. The argument is rounded to an integral value by making use of the current rounding mode.Note: The

current rounding modeis determined, using the`fesetround()`

function.

```
double rint(double x);
float rint(float x);
long double rint(long double x);
double rint(T x);
```

The `rint()`

function takes a single parameter value `x`

, which represents the value taht needs to be rounded to an integral value.

The `rint()`

function returns a value of either type double, float, or long double.

By default, the rounding is done “to the nearest” integer.

#include <iostream>#include <cmath>#include <cfenv>using namespace std;int main(){// creatinn our variablesdouble x = 19.6;double result;// setting rounding direction to DOWNWARD using the fesetround functionfesetround(FE_DOWNWARD);// using the rint() functionresult = rint(x);cout << "Rounding (" << x << ") downward = " << result << endl;return 0;}

Implementing the "rint()" function

**Lines 9–10**: We create the variables`x`

and`result`

.**Line 13**: We set the rounding direction to downward, using the`fesetround()`

function.**Line 16**: We implement the`rint()`

function on the`x`

variable and assign the output to the`result`

variable.**Line 17**: We print the`result`

variable.

RELATED TAGS

functions

c++

communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses