Ở đây chúng ta sẽ xem hàm fdim () trong C ++ là gì. Hàm fdim () được sử dụng để trả về sự khác biệt dương giữa hai đối số đã cho. Nếu hai đối số lần lượt là a và b và nếu a> b, thì nó sẽ trả về a - b. nếu không thì trả về 0.
Ví dụ
#include <cmath>
#include <iostream>
using namespace std;
main() {
cout << "fdim of (5.0, 2.0) is " << fdim(5.0, 2.0) << endl; //positive difference
cout << "fdim of (2.0, 5.0) is " << fdim(2.0, 5.0) << endl; //this will return 0
cout << "fdim of (-5.0, -2.0) is " << fdim(-5.0, -2.0) << endl; //this will return 0
cout << "fdim of (-2.0, -5.0) is " << fdim(-2.0, -5.0) << endl; //positive difference
} Đầu ra
fdim of (5.0, 2.0) is 3 fdim of (2.0, 5.0) is 0 fdim of (-5.0, -2.0) is 0 fdim of (-2.0, -5.0) is 3