Let me try to explain with simple example— Task is to find student whose rank is first and last in class. Before you write code, follow these steps. These will help you in resolving your problem.
Understand what you want to do carefully and define correct problem definition.
we can define our problem as “Find Max and Min Marks from list”
Break down main task into smaller tasks
Task looks easier when you devide it into smaller tasks. Here, You can break down it as--
- Read all student’s names and marks.
- Sort Students by marks in descending order
- Print name of student with first rank as first record from list
- Print name of student with last rank as last record from list
Go further and break down these task again into smaller tasks.
For Ex: Read all student’s names and marks can be break down as follow:
- Define data-structure or variables to hold all student’s names and marks.
- Define input method for reading data.
- Get input and validate.
- Add input to defined database (variable or database)
Always look for alternative.
There is always another way to do it. Before you proceed, check if there is any alternative way of solving problem and select simplest and easiest alternative.
For example in our case, we can solve it other way as follow :
1) Read student’s name and marks
2) Save it into database.
3) Fetch student with Max value of mark from database using database query, print as first rank
4)Fetch student with min value of mark from database using database query, print as last rank
re-think on what you have decided and consider all possibilities to ensure 100% correctness.
Now, as you have list of small task, star coding. Start with simplest task.
Apply above for any programm you want write. If you still find it difficult, For few days, forget about programming and start solving logical puzzles. once you feel you are comfortable with it, come back to programming.
Once you feel more than comfortable with solving these puzzles, come back to programming and try to follow these instructions.
Above All-- as mentioned in every answer to this question- Practice!! Any technique will not work without practice.