Nearby lessons
61 of 124C - Array Operations (Sum, Max, Search)
Array Operations (Sum, Max, Search) is one of the foundational topics in C programming. This lesson explains Program 1: Read and Print an Array, Program 2: Sum and Average and Program 3: Find the Maximum with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Program 1: Read and Print an Array
Example01
Program 2: Sum and Average
Example02
Program 3: Find the Maximum
In simple words: the max program uses a running champion — start with the first element as the champion, then challenge each next element. Whoever is bigger becomes the new champion.
Example03
Program 4: Find the Minimum
Example04
Program 5: Linear Search
Trainer's Note: The search pattern above is called linear search — it checks every element one by one. The trick found = -1 (a value that can never be a valid index) tells us 'not found' at the end.
Example05
📝 Key Takeaways
- Array = same-type values under one name, accessed by index 0 to size-1.
- Declare: int marks[5]; Initialize: int a[3]={1,2,3};
- Use loops to read and print arrays.
- Separate programs: sum/average, max, min, linear search.
- 2D array = table; process with nested loops (rows + columns).
- Matrix addition: c[i][j] = a[i][j] + b[i][j].
🧠 Test Your Knowledge
2 QuestionsProgress: 0 / 2