■ Logic Building Worksheet (Array Programs)
This worksheet helps you practice logic-building for Array programs step-by-step. For each
problem, fill the following 6 steps manually before coding.
Example Problem: Find Maximum Element in Array
Step Question / Task Example Answer
1 Problem Find the largest number in an array
2 Input Array of numbers, e.g., {5, 9, 3, 6, 8}
3 Output Maximum = 9
4 Logic 1■■ Assume first element is max
2■■ Compare with each element
3■■ Update max if bigger found
5 Dry Run Make a table:
i | arr[i] | max(before) | condition | max(after)
6 Code int max = arr[0]; for(int i=1;i<[Link];i++){ if(arr[i]>max){ max=arr[i]; } }
Practice Problems – Fill Step 1 to 6 for each:
[Link] Problem Statement Write Steps (1–6) Here
1 Find minimum element in array
2 Count how many even numbers
3 Find sum and average of array
4 Count positive, negative and zero elements
5 Replace all negative numbers with 0
6 Find second maximum element
7 Search a given element
8 Compare two arrays
9 Count how many prime numbers in array
10 Find product of all array elements
■ Tip: Do at least 2 problems daily. Write your logic, dry run manually, and only then write code.
This builds strong problem-solving skills for interviews and logic tests.