C abs 函数

C abs 函数是用于返回给定数字的绝对正值的 Math 方法之一。abs 的语法如下所示。

int abs(int number);

C abs 函数示例

math abs 函数允许您返回用户给定的数字的绝对正整数。在此程序中,我们将找到相同的值并显示输出。

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

int main()
{
    printf("\n The Absolute Positive Value of 75    = %d ", abs(75));
    printf("\n The Absolute Positive Value of -15   = %d ", abs(15));
    printf("\n The Absolute Positive Value of -152  = %d ", abs(152));
    
    printf("\n The Absolute Positive Value of -14  = %d ", abs(-14));
    printf("\n The Absolute Positive Value of -26  = %d ", abs(-26));
    printf("\n The Absolute Positive Value of 90  = %d \n", abs(90));
    
    return 0;
}
abs function example

abs 示例 2

在此 C 编程 示例中,我们允许用户输入他们的值。接下来,这个 程序 使用 abs 数学 函数来查找绝对正数。

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

int main()
{
    int number;
    
    printf(" Please Enter any Numeric Value :  ");
    scanf("%d", &number);
    
    printf("\n The Absolute Positive Value of %d = %d \n", number, abs(number));
    
    return 0;
}
 Please Enter any Numeric Value :  -987

  The Absolute Positive Value of -987 = 987