Example of how Integer Division works in C/C++

Source:

/**********************************************************************/ /* */ /* Author: Mike Elms */ /* Date: 2/4/2012 */ /* Purpose: To Demonstrate how Integer Division works in C/C++ */ /* */ /**********************************************************************/ #include <iostream> using namespace std; int main() { cout << "Begin" << endl << endl; cout << "Example of Integer Division" << endl << endl; cout << "1/2 = " << 1/2 << endl; cout << "1/3 = " << 1/3 << endl; cout << "2/3 = " << 2/3 << endl; cout << "3/2 = " << 3/2 << endl; cout << endl; cout << "Example of Floating Point Division" << endl << endl; cout << "1.0/2.0 = " << 1.0/2.0 << endl; cout << "1.0/3.0 = " << 1.0/3.0 << endl; cout << "2.0/3.0 = " << 2.0/3.0 << endl; cout << "3.0/2.0 = " << 3.0/2.0 << endl; cout << endl; cout << "End" << endl; }

Output:

Begin Example of Integer Division 1/2 = 0 1/3 = 0 2/3 = 0 3/2 = 1 Example of Floating Point Division 1.0/2.0 = 0.5 1.0/3.0 = 0.333333 2.0/3.0 = 0.666667 3.0/2.0 = 1.5 End