代码:
#include<stdio.h>
int main()
{
int i,n,a,fa,max,maxold;
scanf("%d",&n);
scanf("%d",&a);
max=(a>=0)?a:-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\n",maxold);
return 0;
}
输出结果:
5
-1 2 3 4 -5
-5
--------------------------------
Process exited with return value 0
Press any key to continue . . .