C language
Algorithms
PANCHAL KARTIK J
STUDENT OF COMPUTER ENGINEERING
❖ Topic
 Algorithms
 Type of algorithms
 Pseudo code
 Example
 Exercises
❖ Algorithms
 An algorithms is finite sequence of well defined step or operation for
solving a problem in system manner
 The step by step solving to program
❖ Type of algorithm
 There four type of algorithm
1. Divide and conquer
2. Greedy method
3. Branch and bound
4. Recursion
1. Divide and conquer
 The divide and conquer technique is used to solve complex
problem easily
 Complex problem are decomposed in to several step
2. Greedy method
 This method solve to optimization problem
3. Branch and bound
 When there are several statement or centrain part of logical
repeated this of concept is used
4. Recursion
 When procedure call itself is called recursion
❖ Pseudo code
 It is language or part of language used to cover program into easy
into
 It allow the programming to write logic of flowchart or algorithm in
symbolic form
 There are five type of pseudo code
1. Storage declaration
2. Assignment of any value
3. Procedure call
4. Input / output
5. Constant value
Example
❖ Write an algorithm to find out sum of two number
1. Step 1 : input two number : a , b
2. Step 2 : calculate sum = a + b
3. Step 3 : print “total = “ sum
4. Step 4 : stop
 Step 1 is enter the two number e.g. a = 3 b = 4
 Step 2 is a and b add e.g. 3 + 4
 Step 3 is a print to the sum e.g. 7
 Step 4 is stop to the program
❖ Write an algorithm to reverse
give number
1. Step 1 : input number : num
2. Step 2 : sum = 0
3. Step 3 : repeat from step 3 to step 6 unit num > 0
4. Step 4 : calculate r = num % 10
5. Step 5 : Calculate sum = sum * 10 + r
6. step 6 : calculate num = num / 10
7. Step 7 : print “ reverse number = “ sum
8. Step 8 : stop
❖ Write an algorithm to solve
following series 1! + 2! + ……..+n!
1. Step 1 : input number : num
2. Step 2 : f = 1
3. Step 3 : sum = 0
4. Step 4 : I = 1
5. Step 5 : repeat from step 5 to step 8 unit I < = num
6. Step 6 : f = f * I
7. Step 7 : sum = sum + f
8. Step 8 : I = I + 1
9. Step 9 : print “sum = “ sum
10. Step 10 : stop
C language algorithms

C language algorithms

  • 1.
    C language Algorithms PANCHAL KARTIKJ STUDENT OF COMPUTER ENGINEERING
  • 2.
    ❖ Topic  Algorithms Type of algorithms  Pseudo code  Example  Exercises
  • 3.
    ❖ Algorithms  Analgorithms is finite sequence of well defined step or operation for solving a problem in system manner  The step by step solving to program
  • 4.
    ❖ Type ofalgorithm  There four type of algorithm 1. Divide and conquer 2. Greedy method 3. Branch and bound 4. Recursion
  • 5.
    1. Divide andconquer  The divide and conquer technique is used to solve complex problem easily  Complex problem are decomposed in to several step
  • 6.
    2. Greedy method This method solve to optimization problem
  • 7.
    3. Branch andbound  When there are several statement or centrain part of logical repeated this of concept is used
  • 8.
    4. Recursion  Whenprocedure call itself is called recursion
  • 9.
    ❖ Pseudo code It is language or part of language used to cover program into easy into  It allow the programming to write logic of flowchart or algorithm in symbolic form  There are five type of pseudo code 1. Storage declaration 2. Assignment of any value 3. Procedure call 4. Input / output 5. Constant value
  • 10.
    Example ❖ Write analgorithm to find out sum of two number 1. Step 1 : input two number : a , b 2. Step 2 : calculate sum = a + b 3. Step 3 : print “total = “ sum 4. Step 4 : stop  Step 1 is enter the two number e.g. a = 3 b = 4  Step 2 is a and b add e.g. 3 + 4  Step 3 is a print to the sum e.g. 7  Step 4 is stop to the program
  • 11.
    ❖ Write analgorithm to reverse give number 1. Step 1 : input number : num 2. Step 2 : sum = 0 3. Step 3 : repeat from step 3 to step 6 unit num > 0 4. Step 4 : calculate r = num % 10 5. Step 5 : Calculate sum = sum * 10 + r 6. step 6 : calculate num = num / 10 7. Step 7 : print “ reverse number = “ sum 8. Step 8 : stop
  • 12.
    ❖ Write analgorithm to solve following series 1! + 2! + ……..+n! 1. Step 1 : input number : num 2. Step 2 : f = 1 3. Step 3 : sum = 0 4. Step 4 : I = 1 5. Step 5 : repeat from step 5 to step 8 unit I < = num 6. Step 6 : f = f * I 7. Step 7 : sum = sum + f 8. Step 8 : I = I + 1 9. Step 9 : print “sum = “ sum 10. Step 10 : stop