Hàm modf tách phần nguyên và phần thập phân

double modf( double x, double *intptr);

Parameter:

x: tham số đầu vào double

intptr: con trỏ trỏ tới vùng nhớ lưu giá trị phân nguyên

Remark:

Hàm modf( ) chia số x thành 2 phần: phần nguyên và phần thập phân. Hàm trả về giá trị phần thập phân, phần nguyên được trỏ bởi intptr.

Ví dụ:

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

int main( void )
{
    double x, y, n;

    x = -14.87654321; /* Divide x into its fractional */
    y = modf( x, &n ); /* and integer parts */

    printf( "For %f, the fraction is %f and the integer is %.f\n", 
    x, y, n );
    getch();
}

Kết quả:

Hàm modf tách thành phần nguyên và phần thập phân

Be the first to comment

Leave a Reply