Algorithm in C- free C programming tutorial

In this tutorial you will be familiarize with the algorithm in C programming language.

Algorithm :

An algorithm is defined as a process or set of rules to be followed in calculations or other problem-solving operations or  It can be defined as procedure or formula of solving a problem step by step i.e. sequentially or In algorithms the basic process/plan required to solve given problem is written.

Contents of algorithms :

  1. number of variables
  2. arithmetic or logical operation
  3. conditions

Qualities of good algorithms :

  1. Algorithms should be precise and easy to understand.
  2. Declaration of variables should be done in precise way.
  3. Each step should be clear and easy to understand.
  4.  Algorithms should contain most effective and easy way to solve any problem.
  5.  Algorithms should not contain similar programming code as algorithm is a basic plan or idea to develop a code.

Example of algorithms are given below:

  1. To swap two number
  2. To determine factorial of number entered by user
  3. to determine fibonacci series of number entered by user

Algorithm to swap two number is given below :

step 1.  start
step 2.  read two numbers from user( i.e. x and y)
step 3.  declare a temporary variable
step 4.   //  for swapping
temp = x;
x=y;
y=temp;
step 5.   exit


Algorithm to determine factorial of number entered by user is given below :

step 1.  start
step 2.  read number from the user(n)
step 3.  initialize counter variable(i) with 0 to n
step 4.  if ( i<=num ) go to step 5 otherwise return to step 7
step 5.  calculate fact = fact * i
step 6.  increment counter variable(i) and goto step 4
step 7.  write fact
step 8.  exit


Algorithm to determine fibonacci series of number entered by user is given below :

step 1.  start
step 2.  declare variables i, a,b, fib
step 3.  initialize the variables, a=0 , b=1, and fib =0
step 4. Enter the number of terms of Fibonacci series to be printed
step 5. Print First two terms of series i.e. a and b
step 6. Use for-loop statement for the following steps
-> fib=a+b
-> a=b
-> b=fib
-> increase value of i each time by 1
-> print the value of show
step 7.  exit

If you have any query please comment below.

Leave a Comment

Your email address will not be published. Required fields are marked *