C++ Math remquo()
C++ Math remquo()
该函数查找分子/分母的浮点余数(四舍五入为最接近的整数值),并且还将商数内部存储到所传递的指针中
语法
假设分子为" n",分母为" d",指针为" p"。语法为:
return_type remquo(data_type n, data_type d, int* p);
注意: return_type可以是float,double或long double。
参数
n : 分子的值。
d : 分母的值。
p : 指向内部存储有商的对象的指针。
返回值
它返回浮点余数n/d。
示例1
让我们看一个简单的示例,说明参数的类型相同。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=7.6;
float y=5.4;
int* p;
std::cout << "Value of remainder is :" << remquo(x,y,p)<<'\n';
cout<<"Value of quotient is :"<<*p;
return 0;
}
输出:
Value of remainder is :2.2
Value of quotient is :1
示例2
让我们看一个简单的示例,说明参数的类型不同。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x=2;
float y=1.1;
int* q;
std::cout << "Value of remainder is :" <<remquo(x,y,q)<<'\n';
cout<<"Value of quotient is :"<<*q;
return 0;
}
输出:
Value of remainder is :0.2
Value of quotient is :2