天天看点

abs()求绝对值函数

<b>一、程序代码</b>

# /* Name abs.c

# * Author dyli

# * date 20110711

# * Description deepen understand the math

   * function of abs()    

# *

# * */

# /***abs()函数************************************************

# * 函数功能: 取一个数的绝对值

# * 函数原型:

# * 返回值 : 绝对值

# * 所需库 : math.h

# * 备注 :

# ****************************************************************/

#include stdio.h&gt;

#include math.h&gt;

int main(void)

{    

    int nega_value = 0;

    int posi_value = 0;

    printf("please input a Negative number(fu shu)\n");

    scanf("%d",&amp;nega_value);

    posi_value = abs(nega_value);

    printf("----------&gt;output the absolute value\n\----------&gt;and it must be positive \n");

    printf("look here %d \n",posi_value);

    return 0;

}

<b>二、运行效果</b>

[root@localhost abc]# ls

abs abs.c abs.c~ fopen.txt Makefile

[root@localhost abc]# ./abs

please input a Negative number(fu shu)

-9632

----------&gt;output the absolute value

----------&gt;and it must be positive

look here 9632

[root@localhost abc]#

继续阅读