求绝对值最大值
Time Limit: 1000MS
Memory Limit: 65536KB
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 <math.h>
int main()
{
int n;
int num;
int max = 0;
int i;
scanf("%d",&n);
for(i = 0; i < n; i++)
{
scanf("%d",&num);
if(abs(max) < abs(num))
max = num;
}
printf("%d\n",max);
return 0;
}