Problem E: 求绝对值最大值

版权声明: https://blog.csdn.net/t_jeey/article/details/79517618

Problem E: 求绝对值最大值

Time Limit: 1 Sec  Memory Limit: 64 MB

Description

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

Input

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

Output

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

Sample Input

5
-1 2 3 4 -5

Sample Output

-5

HINT


参考答案:

#include<stdio.h>
int main()
{
	int n;
	int max1=0,a,i,m,x;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a);
		if(a<0)
		{
			a=-a;
			m=-1;
		}
		if(max1<a)
		{
			max1=a;
			x=m;
		}
	}
	printf("%d",max1*x);
	return 0;
}


猜你喜欢

转载自blog.csdn.net/t_jeey/article/details/79517618
今日推荐