求绝对值最大值

来源:互联网 发布:斗鱼裴语燕 知乎 编辑:程序博客网 时间:2024/06/06 12:20

求绝对值最大值

Time Limit: 1000MS Memory Limit: 65536KB

Submit Statistic

Problem Description

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

Input

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

Output

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

Example Input

5
-1 2 3 4 -5

Example Output

-5

Hint

Author

#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){    int n,i,max = 0,cn = 0;    scanf("%d",&n);    int a[n];    for(i = 0;i < n;i++)    {        scanf("%d",&a[i]);        if(a[i]<0)        {            if(max < -a[i])            {                max = -a[i];                cn = i;            }        }        else        {            if(max < a[i])            {                max = a[i];                cn = i;            }        }    }    printf("%d\n",a[cn]);    return 0;}
原创粉丝点击