fdim()函数以及C ++中的示例
C++fdim()函数
fdim()函数是cmath标头的库函数,用于查找两个数字之间的正差,它接受两个数字并返回它们的正差。
fdim()函数语法:
fdim(x, y);
参数:x,y–是要计算其正差的数字。
返回值:double-返回double值,它是数字x和y的正差。
示例
Input:
float x = 20;
float y = 10;
Function call:
fdim(x,y);
Output:
10C++代码演示fdim()函数示例
//示例
//fdim()功能
#include <iostream>
#include <cmath>
using namespace std;
//main()部分
int main(){
float x;
float y;
float result;
//输入数字
cout<<"Enter first number : ";
cin>>x;
cout<<"Enter second number: ";
cin>>y;
//找到积极的区别
result = fdim(x,y);
cout<<"fdim("<<x<<","<<y<<"): "<<result;
cout<<endl;
return 0;
}输出结果
First run: Enter first number : 10 Enter second number: 20 fdim(10,20): 0 Second run: Enter first number : 20 Enter second number: 10 fdim(20,10): 10 Third run: Enter first number : -10.1234 Enter second number: -20.1231 fdim(-10.1234,-20.1231): 9.9997 Fourth run: Enter first number : -20.1231 Enter second number: -10.1234 fdim(-20.1231,-10.1234): 0