求绝对值

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2003

看的时候挺简单的,还在想这上面题也太水了。

做的时候没得换得,提交了两次才发现。

 

#include <stdio.h>

int main()
{
     double a,b;
     while(scanf("%lf",&a)!=EOF)
     {

        b=a;
        if(b<0)
        {
            b=-a;
        }
        printf("%.2lf\n",b);
     }
    return 0;
}

-------------------------------------------------------------------------------


#include <stdio.h>

int main()
{
    double a;
    while(scanf("%lf",&a)!=EOF)
    {
        printf("%.2lf\n",a>0?a:-a);
    }
    return 0;
}

 

posted @ 2010-12-05 10:51  _cc  阅读(238)  评论(0编辑  收藏  举报