![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
fdim() in C++
Here we will see what is the fdim() function in C++. The fdim() function is used to return the positive difference between two given arguments. If two arguments are a and b respectively, and if a >b, then it will return a – b. otherwise returns 0.
Example
#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 }
Output
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
Advertisements