Monday, July 23, 2012

how a programmer should think logically to develop logic for a program-logical thinking tip

What is a logic ?

In a program logic is a code or set of instructions to solve a particular problem. Logic is important in each and every program as every program have some logic to solve the problem.
Logic is a special set of instructions given to the computer. The computer executes the given instructions specified in the logic and solve the problem by using those instructions.

How to think logically ?


Every programmer should think logically in order to develop logic for a program. but the problem arises here is how to think logically ?

 So in order to think logically we should learn how a logic will work and how to develop a logic for a program.

Also read:Introduction To Logical Thinking For a Programmer.

How to develop a logic ?

To develop logic for a program we should be capable of thinking logically. only a logical thinker can be capable of developing logic for a program. but most of the programmers and beginners struggle a lot in order to improve their logical thinking skills.

Points to be remember while developing a logic :-

Feel you are talented than computer:

Always feel that you are talented than computer. This will increase your confidence level.  because computer cannot understand anything unless we write a code for it. we will write logic for a computer to solve a particular problem. so with out your logic a computer cannot solve any problem. so a computer needs your logic in order to solve a particular problem.

Recall all Programming concepts you have learnt:

Developing a logic is nothing but using the available resources in a particular way and achieving solution for the problem. So it is necessary for a programmer to learn all the programming concepts and recall them while developing  logic for a particular problem.

Think in a machine oriented way:

Forget for a while that you are a human being and think that you are a machine. so as a property of a machine that it cant understand anything. so  feel that you cant understand anything. so if a machine cant understand anything, then we will give some instructions for the machine to follow them in order to solve a problem. These instructions are nothing but a logic. 

So by thinking in a machine oriented way, you can be capable to write logic for a program which is used by the computer to solve the problem.

Real Time application of Logic :-

For example if anyone ask you to go to a shop and buy a book, then immediately you began to think about the resources available to you, that is


-> Whether the money provided is sufficient or not. If it is sufficient to buy the book, then you will go forward otherwise you will ask for extra money.

-> Whether there any travelling resources like a bike or car is provided to reach the shop. if it is provided then you will go forward otherwise you will ask them to provide transport facility.

-> After that you will think of reaching the exact place. for this you should think which route is used to reach the desired place. after choosing the desired place then you will go there, buy the book and return back.

So here the task of buying a book is completed. you are a human being and you are capable of thinking yourself to how to buy the particular book. but in case of a machine, it does not have brain and it cant think. so now you should make the computer able to think in order to buy a book. you can make a computer able to think by providing all the steps you have followed manually in the form of instructions to the computer. These instructions are called Logic to solve the problem of buying a book.

While the above example will be little bit confusing and hard to understand so i will give you one more simple example in developing a logic.

If a person asked you to write all the even numbers between 1 to 10. then you will write
2 4 6 8 10.
Just make a clear notes how you thought to achieve the above output.

-> Starting from number 1

-> Checking whether it is even or not. a number which is exactly divisible by 2 is called a even number. it means the remainder should be zero.

-> If the remainder is zero(if it is even) then you will write the number.

-> Then you will go for the next number and check whether the given number is even or not. you will continue the above steps until the number 10.

So now to develop logic to solve the above problem,  give the thinking steps you have followed in the form of instructions to the computer. This behave as a logic to solve the problem of finding even numbers.

Now while developing logic recall the programming concepts and resources and apply them to the above thinking steps which you have followed.

Step 1 :-
we are finding the even numbers continously from 1 to 10. so in a program the concept we use for continous execution of steps is a for loop. we are starting from 1 and repeating the steps until 10 for each and every number between 1 and 10.
so the very first code is
for(i=1;i<=10;i++) /* here i is a variable used to store values */
{

Step 2:-
The second step in the thinking steps you have written is checking whether the given number is even or not.
so in order to check for a condition we use if() statement. and now for checking whether the number is even or not we will divide the number by 2. if the remainder is zero then it is even.
In programming we use % operator to find the remainder. so now the code to find the even number is
if(i%2==0)

Step 3:-
The third step in thinking steps is to print the value if it is even.
The concept we use in programming in order to print some thing is printf();(here taking c programming language as an example). here we are printing a value and that is an integer value so we use
printf("%d ",i);

Step 4:-
The fourth step in thinking steps is to continue the process until all the numbers are checked. so it mean that this is the end of the statements to be executed continously. so from this step it should forward to the starting step. so we should indicate the compiler that the block of statments end here. so we use
}.
so finally the logic for finding even numbers from 1 t 10 is
for(i=1;i<=10;i++)
{
if(i%2==0)
printf("%d ",i);
}

Final conclusion:-

The definition for logic from a programmers point is "making a computer capable to think" or "giving thinking power to computer" is called a logic.

It seems you are interested in Programming. Then check our C Programming Tips.

17 comments:

  1. with out my permission y u have copied this from my blog CODERS HUNT

    ReplyDelete
  2. Respected Admin,

    We have found your article i.e. http://aroundtheworld2k13.wordpress.com/2012/12/22/how-to-think-logically-in-programming-to-develop-logic/ as a complete violation of our copyrights. The article is a duplicate copy of the original post published on CODERSHUNT @ http://www.codershunt.com/2012/06/how-programmer-should-think-logically.html. Republication of such content is a serious loss to our SERP ranking and reputation. We thereby request you to remove the post completely within 48 hours.

    Failure to comply will result in a complete deletion of your article. Your URL will be reported to both AdSense and GOOGLE DMCA. We therefore earnestly believe that you understand the consequences and expect sincere cooperation from your side.

    Original Content URL: http://www.codershunt.com/2012/06/how-programmer-should-think-logically.html

    Duplicate Content URL: http://aroundtheworld2k13.wordpress.com/2012/12/22/how-to-think-logically-in-programming-to-develop-logic/

    Regards,

    doodi srinath reddy

    Founder and Author : www.codershunt.com

    ReplyDelete
  3. this will be helpful :
    http://www.kodingexamples.blogspot.com/2014/03/8-Great-Tips-For-Developing-Logic-in-Programming.html

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. This comment has been removed by a blog administrator.

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. This comment has been removed by a blog administrator.

    ReplyDelete
  14. This comment has been removed by a blog administrator.

    ReplyDelete
  15. I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more. sports surge

    ReplyDelete
  16. Looking for a hassle-free pathway to secure a seat at Vydehi Medical College? College Dhundo offers valuable insights on "Direct Admission In Vydehi Medical College Direct Admission In Vydehi Medical College Explore this informative resource to simplify your admission process and achieve your medical education goals.

    ReplyDelete