5. Algorithm of a computer programming

An algorithm is a step by step method of solving a problem. It is commonly used for data processing, calculation and other related computer and mathematical operations.An algorithm is also used to manipulate data in various ways, such as inserting a new data item, searching for a particular item or sorting an item.

Some examples of algorithm are given below :

1.  Write an algorithm to add given two numbers.

Step 1: Start.
Step 2: Read two numbers A and B.
Step 3: Total = A+B.
Step 4: Display Total.
Step 5: Stop.

2.  Write an algorithm for Subtracting two Numbers.

Step 1: Start.
Step 2: Read two numbers A and B.
Step 3: Answer = A - B.
Step 4: Display SUB.
Step 5: Stop.

3. Write an algorithm to find factorial of a given number.

Step 1: Start
Step 2: Declare variables: N, fact,  i.
Step 3: Initialize variables

            fact = 1

            i = 1

Step 4: Read value of N from user.
Step 5: Repeat following steps until i = N

            fact =  fact * i

            i = i + 1

Step 6: Print fact variable.
Step 7: Stop

4. Write an algorithm to multiply given two numbers.

Step 1: Start.
Step 2: Read two numbers A and B.
Step 3: Answer = A * B.
Step 4: Display Answer.
Step 5: Stop.


5.  Write an algorithm for dividing given two numbers.

Step 1: Start.
Step 2: Read two numbers A and B.
Step 3: Answer = A / B.
Step 4: Display Answer.
Step 5: Stop.

Comments

Popular posts from this blog

12. Library Functions of C Programming

13. Control Strings in C Programming

4. What is Compiler ?

10. Data Types of C Programming

3. What is programming language ?

7. Introduction of C programming :

9. Header Files of C Programming

18. Identifiers and Keyword in C programming

8. Program structure rules of C programming