C Programming Notes
C Programming Notes - Units 1, 2, and 3
Unit-1
# Unit-1
### Question 1: Define Algorithm? What are the characteristics? Write an example of algorithm.
Algorithm: An algorithm is a finite set of well-defined, logical instructions or steps for solving a
problem or performing a specific task. Algorithms are widely used in computer programming and
other disciplines to design efficient and effective solutions to problems. An algorithm should be
language-independent and focus on the logical flow of operations.
Characteristics of an Algorithm:
1. Finiteness: An algorithm must terminate after a finite number of steps. It should not run
indefinitely.
2. Definiteness: Each step of the algorithm must be precisely defined. There should be no ambiguity
in the instructions.
3. Input: An algorithm should have zero or more well-defined inputs.
4. Output: An algorithm must produce at least one output that is related to the given inputs.
5. Effectiveness: The operations described in the algorithm should be basic enough to be executed
using available resources.
6. Generality: The algorithm should solve a class of problems, not just a single problem.
Example of an Algorithm:
C Programming Notes
Algorithm to find the sum of two numbers:
1. Start.
2. Input two numbers, say a and b.
3. Calculate the sum of a and b using the formula: sum = a + b.
4. Display the result, i.e., sum.
5. Stop.
Detailed Explanation:
Let us consider two numbers, for instance, a = 10 and b = 20. By following the above steps, the
algorithm takes these numbers as input, calculates their sum (10 + 20 = 30), and produces the
output 30. The algorithm terminates after printing the result, ensuring finiteness and definiteness.
This is a simple example, but the principles apply to more complex algorithms, such as sorting or
searching.