Posts

Showing posts with the label learn to code

How to write Algorithms

How to write Algorithms for solving problems? Algorithm: An algorithm is the set of rules that are needed to be followed while solving problems. Here we'll learn how to write algorithms for the given simple problems. Tips for writing an algorithm : Read the problem carefully. Don't start writing the code immediately. It is always best to start with the algorithm. After understanding the problem, think about the logic required to solve the problem. Once you root out the logic behind the problem, then start writing the algorithm which is nothing but the procedures of solving the problem in a step wise manner. Problem 1: To check whether the given number is positive or negative. Input:  A number Output:  Positive or negative Procedure: Step 1 : Start Step 2 : Read the number(n) from the user. Step 3 : If the number is less than zero, print "negative". If the number is greater than zero, print "positive". Step 4 : End Problem 2: To check whether the given number