div()Prototype: div_t div(int numerator, int denominator);Header File: stdlib.h (C) or cstdlib (C++) Explanation: Div takes a fraction (numerator/denominator) and places the quotient and the remainder into the struct it returns, div_t. In div_t the two ints are quot and rem, quotient and remainder. Example:
//Example shows division
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
div_t answer;
answer = div(76, 5)
cout<<"As an improper fraction, 76/5";
cout<<"As a proper fraction, "<<div_t.quot<<" "<< div_t.rem<<"/5";
}
Other Functions
|