Wednesday, March 17, 2021

, ,

fmod() function in C++

 fmod() function in C++ very useful for computes the floating point remainder of numerator/denominator (rounded towards zero).

Syntax for fmod() C++

fmod (x, y) = x - tquote * y

fmod() prototype

double fmod(double x, double y);
float fmod(float x, float y);
long double fmod(long double x, long double y);
double fmod(Type1 x, Type2 y); // Additional overloads for other combinations of arithmetic types

fmod() function in c++ takes two arguments and returns a value with the type of double, float or long double type.

fmod() C++ Parameters


    x as The value of numerator.
    y as The value of denominator.

Example 1 for How fmod() works in C++?


#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    double x = 7.5, y = 2.1;
    double result = fmod(x, y);
    cout << "Remainder of " << x << "/" << y << " = " << result << endl;
    
    x = -17.50, y = 2.0;
    result = fmod(x, y);
    cout << "Remainder of " << x << "/" << y << " = " << result << endl;
    
    return 0;
}

OUTPUT : - 

fmod c++ example
OUTPUT



0 comments:

Post a Comment