C Programming- Algorithm and Flowchart

Redmen Ishab
2 min readApr 2, 2022

What is Algorithm ?

A process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.

Why Algorithm ?

An algorithm is important in optimizing a computer program according to the available resources. .

What makes a better Algorithm ?

Ultimately when anyone decide to solve a problem through better algorithms then searching for the best combination of program speed and least amount of memory consumption is desired.

Types Of Algorithm :

  1. Brute Force
  2. Divide and Conquer
  3. Decrease and Conquer
  4. Dynamic Programming
  5. Greedy Algorithm
  6. Transform and Conquer
  7. Back Tracking Algorithm

Steps Of Writing An Algorithm:

  1. Obtain a description of the problem.
  2. Analyze the problem.
  3. Develop a high level algorithm.
  4. Refine the algorithm with extra details.
  5. Review and Implement the algorithm.

Problem: I need a send a birthday card to my brother, Animesh.

Analysis: I don’t have a card. I prefer to buy a card rather than make one myself.
High-level algorithm:

Go to a store that sells greeting cards
Select a card
Purchase a card
Mail the card
This algorithm is satisfactory for daily use, but it lacks details that would have to be added were a computer to carry out the solution. These details include answers to questions such as the following.

“Which store will I visit?”
“How will I get there: walk, drive, ride my bicycle, take the bus?”
“What kind of card does Animesh like: humorous, sentimental, risqué?”

Flowchart

A graphical representation of steps of a computer program in relation to solution to a problem.

Diagrams used in flowchart :

flowchart diagrams

Conventions to be used in developing Algorithm and Flowchart:

  1. Each algorithm must be enclosed within START and STOP.
  2. Use keyword INPUT or READ to take user’s input.
  3. Use keyword PRINT or DISPLAY to show outputs to user.
  4. Arithmetical operators (+, -, *, /, etc) are used in mathematical expressions.
  5. Relational operators ( >, ==, ≥ etc) are used in conditions.
  6. Logical operators (AND, NOT, OR, etc) are used for logical expressions.

Exercise:

  1. Write an algorithm and draw flowchart for finding the sum of any two numbers.
    Algorithm:
    i. Start
    ii. Display “Enter two numbers”
    iii. Read A and B
    iv. C= A+B
    v. Display “C as the sum of two numbers”.
    vi. Stop.
  2. Calculate Simple Interest (SI = (P*T*R)/100)
  3. Find greatest number among 3 different numbers A, B and C.
  4. Sum of N numbers ( sum= 1+2+3 …).

--

--

Redmen Ishab

Software Engineer. Failed startup “Software Factory”. Working experience as CTO, SSE, Full Stack Dev, Mobile App Engineer, and Lecturer.