當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C語言 modf()用法及代碼示例

這個函數解決了一些基本的數學問題,這些問題在編程中會非常複雜。

這個modf()函數有兩個參數,第一個是需要處理的浮點值,第二個是整數的地址。

如果第一個參數,則函數返回小數值,並將剩餘的整數存儲在已傳遞給函數的整數中。

例:

    X = 10.858 
    Function will return 0.858 
    Function will store the value in the integer = 10

該函數是math.h在使用此函數之前應包含在程序中的庫。

math.h - C 中的 modf() 函數示例


#include <stdio.h>
#include <math.h>

int main()
{
	// Defining variables
	double a,b,c;

	// Assigning value for getting modf value
	a = 54.545;

	// Calculating floating-point value into 
	//an integer and a fractional part
	c = modf(a, &b);

	// Displaying the result for the user
	printf("The calculated value is:%lf \n\n", c);

	return 0;
}

輸出

math.h - modf()  in c language



相關用法


注:本文由純淨天空篩選整理自Manu Jemini大神的英文原創作品 modf() function of math.h in C。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。