C 求绝对值的最大值 SDUT


Description

求n个整数中的绝对值最大的数。


Input

输入数据有2行,第一行为n,第二行是n个整数。


Output

输出n个整数中绝对值最大的数。


Sample
Input

5
-1 2 3 4 -5


Output

-5


本题一定要知道绝对值函数abs(),这个函数在后面的学习中也有多处用到

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,a,max=0,x;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&a);

        if(abs(max) < abs(a))
            max=a;
    }
    printf("%d",max);
    return 0;
}
发布了136 篇原创文章 · 获赞 95 · 访问量 2324

猜你喜欢

转载自blog.csdn.net/zhangzhaolin12/article/details/103949528
今日推荐