How I Learnt Logic Building in Programming! – 5 Tips To Build & Improve Programming Logic

Tip #1: Divide & Conquer

Always divide the problem in different parts.
For Example

This is a C code that just input for a number one and and a number two and simply add them.

#include <stdio.h>

int main(void)
{


This content originally appeared on DEV Community and was authored by Muhammad Maaz Shakeel

Tip #1: Divide & Conquer

Always divide the problem in different parts.

For Example

This is a C code that just input for a number one and and a number two and simply add them.

   #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 return the value of addition of those numbers that inputted from the user.
Lets Divide the code

   #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 it's own
component. And you can create a file for that component and import that component.

So, You can break the code into it's own components in your own application. This will be more clean and more readable code.

Tip #2: Write a well-commented code

Write comments on every line of code, that explaining your code of line.
So, Lets take the example of the code and write comments on that code we used in the last tip.

For Example

   #include <stdio.h>

   int add(int number1, int number2);   

   int main(void)
   {
       // Created the variable called num1 that will store the number of the input given from the user
       int num1;
       printf("Number One: ");
       scanf("%i", &num1);
       // Created the variable called num2 that will store the number of the input given from the user
       int num2;
       printf("Number One: ");
       scanf("%i", &num2);
       // Created a variable and stored the sum of those numbers in that variable by calling add function
       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 explains your every line 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 over 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 works 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 it. 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.


This content originally appeared on DEV Community and was authored by Muhammad Maaz Shakeel


Print Share Comment Cite Upload Translate Updates
APA

Muhammad Maaz Shakeel | Sciencx (2021-06-26T17:01:08+00:00) How I Learnt Logic Building in Programming! – 5 Tips To Build & Improve Programming Logic. Retrieved from https://www.scien.cx/2021/06/26/how-i-learnt-logic-building-in-programming-5-tips-to-build-improve-programming-logic/

MLA
" » How I Learnt Logic Building in Programming! – 5 Tips To Build & Improve Programming Logic." Muhammad Maaz Shakeel | Sciencx - Saturday June 26, 2021, https://www.scien.cx/2021/06/26/how-i-learnt-logic-building-in-programming-5-tips-to-build-improve-programming-logic/
HARVARD
Muhammad Maaz Shakeel | Sciencx Saturday June 26, 2021 » How I Learnt Logic Building in Programming! – 5 Tips To Build & Improve Programming Logic., viewed ,<https://www.scien.cx/2021/06/26/how-i-learnt-logic-building-in-programming-5-tips-to-build-improve-programming-logic/>
VANCOUVER
Muhammad Maaz Shakeel | Sciencx - » How I Learnt Logic Building in Programming! – 5 Tips To Build & Improve Programming Logic. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/26/how-i-learnt-logic-building-in-programming-5-tips-to-build-improve-programming-logic/
CHICAGO
" » How I Learnt Logic Building in Programming! – 5 Tips To Build & Improve Programming Logic." Muhammad Maaz Shakeel | Sciencx - Accessed . https://www.scien.cx/2021/06/26/how-i-learnt-logic-building-in-programming-5-tips-to-build-improve-programming-logic/
IEEE
" » How I Learnt Logic Building in Programming! – 5 Tips To Build & Improve Programming Logic." Muhammad Maaz Shakeel | Sciencx [Online]. Available: https://www.scien.cx/2021/06/26/how-i-learnt-logic-building-in-programming-5-tips-to-build-improve-programming-logic/. [Accessed: ]
rf:citation
» How I Learnt Logic Building in Programming! – 5 Tips To Build & Improve Programming Logic | Muhammad Maaz Shakeel | Sciencx | https://www.scien.cx/2021/06/26/how-i-learnt-logic-building-in-programming-5-tips-to-build-improve-programming-logic/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.