ฟังก์ชันไลบรารี C / C++ div_t div (จำนวน int, ตัวหาร int) แบ่งตัวเลข (ตัวเศษ) ด้วยตัวส่วน (ตัวส่วน) ต่อไปนี้เป็นการประกาศสำหรับฟังก์ชัน div()
div_t div(int numer, int denom)
พารามิเตอร์เป็นตัวเศษและตัวส่วน ฟังก์ชันนี้ส่งคืนค่าในโครงสร้างที่กำหนดไว้ใน
ตัวอย่าง
#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);
} ผลลัพธ์
Quotient part of (27/ 4) = 6 Remainder part of (27/4) = 3 Quotient part of (27/ 3) = 9 Remainder part of (27/3) = 0