Index of Maximum Element
Find index of maximum element.
BeginnerPhase 4 - Level 1: Basic ArraysExample 7 of 10
index-of-maximum-element.py
1# Take array2n = int(input("Enter array size: "))3arr = []4for i in range(n):5 arr.append(int(input(f"Element {i+1}: ")))67# Find index of max8max_index = 09max_value = arr[0]1011for i in range(1, len(arr)):12 if arr[i] > max_value:13 max_value = arr[i]14 max_index = i1516print(f"Index of maximum: {max_index}")
Output
Enter array size: 5 Element 1: 10 Element 2: 25 Element 3: 5 Element 4: 30 Element 5: 15 Index of maximum: 3
What's going on
Track both value and index.
Key Concepts:
Initialize with first element
Track index when updating max
Print index of maximum
🔗Related Content
- 📖
Phase 4 - Learn Concepts
Review Phase 4 concepts and explanations
- 📝
Phase 4 - Quiz
Test your Phase 4 understanding with quiz questions
- 💻
Phase 4 - All Practice Problems
Explore all practice problems for Phase 4
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum