C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Math Remainder()

C++ Math Remainder()

该函数查找分子/分母的浮点余数(四舍五入为最接近的整数值)。

余数公式:

Remainder = numerator-(r*denominator)
其中,r =分子/分母,并四舍五入为最接近的整数值。

语法

考虑分子" n"和分母" d"。语法为:
return_type remainder(data_type n,data_type d);
注意: return_type可以是float,double或long double。

参数

n : 分子的值。
d : 分母的值。

返回值

它返回n/d的浮点余数。

示例1

让我们看一个简单的示例。
#include <iostream>
#include<math.h>
#include <cfenv>
using namespace std;
int main()
{
    float n=5.7;
    float d=8.9;
    std::cout << "Values of numerator and denominator are :" <<n <<" , "<<d<<std::endl;
    cout<<"Remainder is :"<<remainder(n,d);
    return 0;
}
输出:
Values of numerator and denominator are :5.7 , 8.9
Remainder is :-3.2   

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4