Home » C++ programming language

fmod() function with example in C++

C++ fmod() function: Here, we are going to learn about the fmod() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on April 27, 2019

C++ floor() function

fmod() function is a library function of cmath header, it is used to find the remainder of the division, it accepts two numbers (numerator and denominator) and returns the floating-point remainder of numerator/denominator which is rounded towards to zero.

Syntax of fmod() function:

    fmod(n, m);

Parameter(s): n,m – are the numbers (numerator, denominator) to be used to calculate the remainder of the division.

Return value: double – it returns double type value that is floating-point remainder of the division.

Example:

    Input:
    float n = 5.3;
    float m = 2;
    
    Function call:
    fmod(n,m);
    
    Output:
    1.3

C++ code to demonstrate the example of fmod() function

// C++ code to demonstrate the example of 
// fmod() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    float n;
    float m;
    float result;
    
    //input the value of 
    //numerator and denominator
    cout<<"Enter the value of numerator  : ";
    cin>>n;
    cout<<"Enter the value of denominator: ";
    cin>>m;
    
    //finding the remainder
    result = fmod(n,m);
    cout<<"floating-point remainder of "<<n<<"/"<<m<<" is: ";
    cout<<result<<endl;

    return 0;
}

Output

Enter the value of numerator: 5.3
Enter the value of denominator: 2
floating-point remainder of 5.3/2 is: 1.3

Second run:
Enter the value of numerator: 18.5 
Enter the value of denominator: 4.2
floating-point remainder of 18.5/4.2 is: 1.7

Third run:
Enter the value of numerator: -36.23 
Enter the value of denominator: 24.1 
floating-point remainder of -36.23/24.1 is: -12.13 

Fourth run:
Enter the value of numerator: 36.23
Enter the value of denominator: -24.1
floating-point remainder of 36.23/-24.1 is: 12.13






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.