PTA-求最大值及其下标

简介: 求最大值及其下标

本题要求编写程序,找出给定的n个数中的最大值及其对应的最小下标(下标从0开始)。

输入格式:
输入在第一行中给出一个正整数n(1<n≤10)。第二行输入n个整数,用空格分开。

输出格式:
在一行中输出最大值及最大值的最小下标,中间用一个空格分开。

输入:
6
2 8 10 1 9 10

输出:
10 2

答案:

include

int main(){
int n,a[],k,b;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
b=a[0];k=0;
for(int i=0;i<n;i++){
if(b<a[i]){
b=a[i];
k=i;
}
}
printf("%d %d\n",b,k);

}

相关文章
|
2月前
PTA-求n个数的最大值、最小值、平均值
求n个数的最大值、最小值、平均值
75 2
|
2月前
|
人工智能
PTA-一维数组最大值和最小值交换
一维数组最大值和最小值交换
55 0
|
2月前
|
人工智能 SDN
PTA-求3×4数组中大于等于平均值的元素的和
求3×4数组中大于等于平均值的元素的和
31 1
|
2月前
|
人工智能
PTA-找出整型数组中最大值的函数
找出整型数组中最大值的函数
64 0
|
2月前
PTA-求n个数的平均值最大值最小值问题
求n个数的平均值最大值最小值问题
29 0
|
2月前
|
人工智能
PTA-将数组中的数逆序存放
将数组中的数逆序存放
36 0
|
11月前
7-10 求最大值及其下标
本题要求编写程序,找出给定的n个数中的最大值及其对应的最小下标(下标从0开始)。
93 0
|
C++
acwing 716. 最大数和它的位置 int的最大值和最小值
acwing 716. 最大数和它的位置 int的最大值和最小值
63 0
51nod 1292 字符串中的最大值 V2 (后缀数组)
51nod 1292 字符串中的最大值 V2 (后缀数组)
41 0
|
Java 测试技术 C++
LeetCode 69. Sqrt(x)--(数组)--二分法查找 --简单
Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to be a non-negative integer. Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.
108 0
LeetCode 69. Sqrt(x)--(数组)--二分法查找 --简单