
C 速查手冊
11.1.3 fmin()
math.h 的函數 (function) fmin() 回傳兩個參數 (parameter) 中的最小值,預設回傳值 (return value) 及參數的資料型態 (data type) 為 double ,另有 float 型態的 fminf() , long double 型態的 fminl() 。
fmin() 的函數原型 (prototype) 如下
| double fmin(double, double); |
| float fminf(float, float); |
| long double fminl(long double, long double); |
以下程式示範函數 fmin() 的使用
#include <stdio.h>
#include <math.h>
int main(void)
{
printf("%f\n", fmin(33, 22));
printf("%f\n", fmin(-33, -22));
printf("%f\n", fmin(33, -22));
printf("%f\n", fmin(-33, 22));
printf("%f\n", fmin(33 - 22, 22 - 33));
printf("%f\n", fmin(33 + 22, 22 + 33));
return 0;
}
/* 《程式語言教學誌》的範例程式
http://kaiching.org/
檔名:cmin.c
功能:示範 math.h 中函數 fmin() 的使用
作者:張凱慶 */
編譯後執行,結果如下
| $ gcc cmin.c |
| $ a.out |
| 22.000000 |
| -33.000000 |
| -22.000000 |
| -33.000000 |
| -11.000000 |
| 55.000000 |
| $ |
