How I Learnt Logic Building in Programming! - 5 Tips To Build & Improve Programming Logic
Published: 2021-06-26 17:01:08

### Tip #1: Divide & Conquer


   Always divide the problem into different parts.   
   **For Example** 


***This is a C code that just input for a number one and a number two and simply add them.***
  ```c
   #include <stdio.h>
   
   int main(void)
   {
       int num1;
       printf("Number One: ");
       scanf("%i", &num1);
       int num2;
       printf("Number One: ");
       scanf("%i", &num2);
       printf("The Addition ofjavascrip those numbers is: %i", num1 + num2);
   }
   ```
**This program just adding two numbers inputted from the user. So, we can just divide this code.**


***So, How are we going to divide this code, Well we can create a function called add that just returns the value of the addition of those numbers that inputted from the user?***
`Let's Divide the code`
```c
   #include <stdio.h>

   int add(int number1, int number2);   

   int main(void)
   {
       int num1;
       printf("Number One: ");
       scanf("%i", &num1);
       int num2;
       printf("Number One: ");
       scanf("%i", &num2);
       int addition = add(num1, num2);
       printf("The addition of those numbers is: %i", addition);
   }
   int add(int number1, int number2)
   {
       return number1 + number2;
   }
```
**So, We divided the code. This was an example of a simple program. Maybe you have a complex program, so you can divide them into functions or maybe you are making an app in react native.**


***React-Native lets you break the code into its own component. And you can create a file for that component and import that component.*** 

**So, You can break the code into its own components in your own application. This will be cleaner and more readable code.**

### Tip #2: Write a well-commented code


Write comments on your code, that explaining your code that what that block of code is actually doing.

**So, Let's take the example of the code and write comments on that code we used in the last tip.**
#### **For Example**
```c
   #include <stdio.h>

   int add(int number1, int number2);   

   int main(void)
   {
       // Getting input from the user
       int num1;
       printf("Number One: ");
       scanf("%i", &num1);r
       int num2;
       printf("Number One: ");
       scanf("%i", &num2);
       // Adding the numbers
       int addition = add(num1, num2);
       // Printing the Output
       printf("The addition of those numbers is: %i", addition);
   }
   // This function add simply returns the sum of two numbers
   int add(int number1, int number2)
   {
       return number1 + number2;
   }
```
So, write comments that explain your block of code.
### Tip #3. Learn Data structures and algorithms


**Programming is all about data structure and algorithms. `Data structures` are the fundamentals of all programming languages. It means that if you want to have a good command of any programming language, then you should start with the `data structures` of that programming language.**

**If you get a better command over the `data structure` of programming languages, then you can quickly improve your `programming logic` for that language. Now you know the best way of how to develop logical thinking in programming.**
### 4. Learn about Programming paradigms


**It would help if you also tried to learn the programming paradigms. There are many types of `programming paradigms`. One of the most popular `programming paradigms` is `object-oriented programming`. The programming paradigms also work as the blueprint.**

**With the help of this blueprint, you follow a predefined path to create the projects. It would help if you created plenty of projects using the same `programming paradigms` to have proper command over them. It will help you to improve your `programming logic`.** 
### 5. Start exploring code from experts


**There are hundreds of ways to write a `program` to solve a particular problem. In programming, we have many ways to solve many problems. You may use different logic to solve the problem. And the other programming may use different logic to solve the same problem. That programmer might use the most optimal and straightforward way to solve the problem.**

**Therefore you should look at other people’s code; it will help you to advance as a programmer. `Github` is one of the most `popular programming platforms` where you can see a lot of great projects and lots of programmers to solve the most `complex problems` with a short length of code.**

#### So, I hope this will going to be helpful for you. Thanks for reading.