C++ boost::rational














































C++ boost::rational



Description:-
The header rational.hpp provides an implementation of rational numbers.
Rational number - Number which can be written in form of fraction are called rational numbers .
Syntax:
boost::rational<data_type>

Header File:
#include <boost/rational.hpp>

Sample code:
-----------------------------------------------------------------------------------------------------------------------------------------------------------
#include <boost/rational.hpp>
#include <iostream>

using R = boost::rational<int>;

int main() {

std::cout <<R(5,9) << "\n";

}
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Prints

5/9



Source code:  Addition of rational numbers.
--------------------------------------------------------------------------------------------
#include <boost/rational.hpp>
#include <iostream>

using R = boost::rational<int>;

int main() {
std::cout << "7 + 5/9= " << 7 + R(5,9) << "\n";
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------
Prints

7 + 5/9= 68/9

More Articles of DINESH GOUDA:

Name Views Likes
C++ boost::rational 155 1
program to convert a given binary tree to doubly linked list. 220 4

Comments