测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A41131. 最大数位置

填空题 容易

题目描述

最大数位置

题目描述

输入n个整数,存放在数组a[1]至a[n]中,输出最大数所在位置(n≤1000)。

输入格式

第一行,数的个数n;

第二行,n个正整数,每个数在232−1之内。

输出格式

最大数所在位置。

样例输入

5

67 43 90 78 32

样例输出

3

参考答案

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int main() { int a[1001]; int max; int n, i, t; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &a[i]); max = a[1]; t = 1; for (i = 1; i <= n; i++) { if (max < a[i]) { max = a[i]; t = i; } } printf("%d\n", t); return 0; }
上一题 下一题