游客 Signup | Login
中文 | En

1473 - 《C语言程序设计》江宝钏主编-习题5-3-动态最大值

输入一个正整数n,在输入n个整数,输出n个数中的最大数。

Input

第一行n

第二行n个数

Output

最大的数

Examples

Input

10
1 2 3 4 5 6 7 8 9 10

Output

10

Solution C

#include <stdio.h>
int main(void)
{
	int a[100],z,i;
	scanf("%d",&i);
	while(i>0)
	{
		scanf("%d",&a[i]);
		if (z<=a[i])
		z=a[i];
		i--;
	}
	printf("%d",z);
	return 0;
}

Solution C++

#include<iostream>
using namespace std;
int main()
{
	int n,x,max;
	cin>>n>>x;
	max=x;
	for (int i=2; i<=n; i++)
	{
		cin>>x;
		if (max<x) max=x;
	}
	cout<<max<<endl;
	return 0;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题