Hàm abs tính giá trị tuyệt đối

int abs(int n);
long labs(long n);

Parameter:

n: đầu vào

Remark:

Hàm abs( ) (labs()) trả về trị tuyệt đối của n.

Ví dụ:

#include "stdio.h"
#include "conio.h"
#include "stdlib.h"

void main()
{
    int x = -123;
    long y = -134L;

    printf("abs(%d) = %d", x, abs(x));
    printf("\nlabs(%d) = %d", y, labs(y));

    getch(); 
}

Kết quả:

Hàm abs tính giá trị tuyệt đối

Be the first to comment

Leave a Reply