- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
div() function in C++
The C / C++ library function div_t div(int numer, int denom) divides numer (numerator) by denom (denominator). Following is the declaration for div() function.
div_t div(int numer, int denom)
The parameters are numerator and the denominator. This function returns the value in a structure defined in <cstdlib>, which has two members. For div_t:int quot; int rem;
Example
#include <iostream> #include <cstdlib> using namespace std; int main () { div_t output; output = div(27, 4); cout << "Quotient part of (27/ 4) = " << output.quot << endl; cout << "Remainder part of (27/4) = " << output.rem << endl; output = div(27, 3); cout << "Quotient part of (27/ 3) = " << output.quot << endl; cout << "Remainder part of (27/3) = " << output.rem << endl; return(0); }
Output
Quotient part of (27/ 4) = 6 Remainder part of (27/4) = 3 Quotient part of (27/ 3) = 9 Remainder part of (27/3) = 0
Advertisements