求绝对值最大值

来源:互联网 发布:淘宝怎样注销实名认证 编辑:程序博客网 时间:2024/06/13 02:33

求绝对值最大值

Time Limit: 1000MS Memory Limit: 65536KB
SubmitStatistic

Problem Description

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

Input

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

Output

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

Example Input

5-1 2 3 4 -5

Example Output

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