SlideShare a Scribd company logo
1 of 19
Algorithm Development
• Algorithm is the sequence of steps to be
  performed in order to solve a problem by the
  computer.
Properties of Algorithm
• The given problem should be broken down
  into simple and meaningful steps.

• The step should be numbered sequentially.

• The steps should be descriptive and written in
  simple English.
Advantages of Algorithms
• Reduce Complexity by dividing the program
  into simple and meaningful parts.
• Increase Flexibility Algorithm is written so that
  the code may be written in any language.
• Ease of Understanding No need to understand
  a particular programming language to
  understand an algorithm.
How to write?
• Pseudocode is an artificial and informal
  language that helps programmers to develop
  algorithms.
        – Pseudocode is very similar to everyday English.


• Two Steps to write an algorithm:-

        – First produce a general algorithm (one can use pseudocode)

        – Refine the algorithm successively to get step by step detailed
          algorithm that is very close to a computer language.
• Example 1: Write an algorithm to determine a
  student’s final grade and indicate whether it is
  passing or failing. The final grade is calculated
  as the average of four marks.
Example
Pseudocode:
• Input a set of 4 marks
• Calculate their average by summing and dividing by 4
• if average is below 50
       Print “FAIL”
  else
       Print “PASS”
• Detailed Algorithm
•    Step 1:       Input M1,M2,M3,M4
     Step 2:       GRADE (M1+M2+M3+M4)/4
     Step 3:       if (GRADE < 50) then
                          Print “FAIL”
                   else
                          Print “PASS”
                   endif
• Write an algorithm to convert the length in
  feet to centimeter.
Pseudocode:
• Input the length in feet (Lft)
• Calculate the length in cm (Lcm) by
  multiplying LFT with 30
• Print length in cm (LCM)
Algorithm
• Step 1: Input Lft
• Step 2: Lcm Lft x 30
• Step 3: Print Lcm
• Write an algorithm that will calculate the roots of a
  quadratic equation

• Hint: d = sqrt (b2 4ac ), and the roots are:
       x1 = (–b + d)/2a and x2 = (–b – d)/2a
Pseudocode:
• Input the coefficients (a, b, c) of the quadratic
  equation
• Calculate d
• Calculate x1
• Calculate x2
• Print x1 and x2
Algorithm:
•   Step 1:   Input a, b, c
•   Step 2:   d sqrt (b b 4 a c )
•   Step 3:   x1 (–b + d) / (2 x a)
•   Step 4:   x2 (–b – d) / (2 x a)
•   Step 5:   Print x1, x2
Write an algorithm that reads two values, determines the largest
value and prints the largest value with an identifying message.
ALGORITHM
Step 1:        Input VALUE1, VALUE2
Step 2:        if (VALUE1 > VALUE2) then
                       MAX VALUE1
               else
                       MAX VALUE2
               endif
Step 3:        Print “The largest value is”, MAX
Write an algorithm that reads three numbers and prints the value of
the largest number.

Step 1: Input N1, N2, N3
Step 2: if (N1>N2) then
             if (N1>N3) then
                  MAX N1       [N1>N2, N1>N3]
            else
                  MAX N3       [N3>N1>N2]
            endif
        else
            if (N2>N3) then
                  MAX N2       [N2>N1, N2>N3]
            else
                  MAX N3       [N3>N2>N1]
           endif
        endif
Step 3: Print “The largest number is”, MAX
Example

               Bonus Schedule
OVERTIME – (2/3)*ABSENT   Bonus Paid


>40 hours                 $50
>30 but 40 hours          $40
>20 but 30 hours          $30
>10 but 20 hours          $20
  10 hours                $10
•   Step 1: Input NAME,OVERTIME,ABSENT
•   Step 2: if (OVERTIME–(2/3)*ABSENT > 40) then
•            PAYMENT       50
•         else if (OVERTIME–(2/3)*ABSENT > 30) then
•            PAYMENT        40
•         else if (OVERTIME–(2/3)*ABSENT > 20) then
•            PAYMENT        30
•         else if (OVERTIME–(2/3)*ABSENT > 10) then
•            PAYMENT       20
•         else
•            PAYMENT       10
•          endif
•   Step 3: Print “Bonus for”, NAME “is $”, PAYMENT
Assignment #1

More Related Content

What's hot

2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problemFrankie Jones
 
Fundamental Programming Lect 4
Fundamental Programming Lect 4Fundamental Programming Lect 4
Fundamental Programming Lect 4Namrah Erum
 
Algorithms and how to write an algorithms
Algorithms and how to write an algorithmsAlgorithms and how to write an algorithms
Algorithms and how to write an algorithmsAhmed Nobi
 
8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solving8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solvingKhan Yousafzai
 
1153 algorithms%20and%20flowcharts
1153 algorithms%20and%20flowcharts1153 algorithms%20and%20flowcharts
1153 algorithms%20and%20flowchartsDani Garnida
 
Algorithms and flowcharts1
Algorithms and flowcharts1Algorithms and flowcharts1
Algorithms and flowcharts1Lincoln School
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithmDHANIK VIKRANT
 
Csc 130 class 2 problem analysis and flow charts(2)
Csc 130 class 2   problem analysis and flow charts(2)Csc 130 class 2   problem analysis and flow charts(2)
Csc 130 class 2 problem analysis and flow charts(2)Puneet narula
 
Algorithmsandflowcharts2
Algorithmsandflowcharts2Algorithmsandflowcharts2
Algorithmsandflowcharts2Darlene Interno
 
Chapter 6 algorithms and flow charts
Chapter 6  algorithms and flow chartsChapter 6  algorithms and flow charts
Chapter 6 algorithms and flow chartsPraveen M Jigajinni
 
Chapter 2 Representation Of Algorithms 2
Chapter 2  Representation Of  Algorithms 2Chapter 2  Representation Of  Algorithms 2
Chapter 2 Representation Of Algorithms 2Li-Anne Serrano
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 

What's hot (20)

2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem
 
Fundamental Programming Lect 4
Fundamental Programming Lect 4Fundamental Programming Lect 4
Fundamental Programming Lect 4
 
Writing algorithms
Writing algorithmsWriting algorithms
Writing algorithms
 
Algorithms and how to write an algorithms
Algorithms and how to write an algorithmsAlgorithms and how to write an algorithms
Algorithms and how to write an algorithms
 
8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solving8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solving
 
1153 algorithms%20and%20flowcharts
1153 algorithms%20and%20flowcharts1153 algorithms%20and%20flowcharts
1153 algorithms%20and%20flowcharts
 
Algorithms and flowcharts1
Algorithms and flowcharts1Algorithms and flowcharts1
Algorithms and flowcharts1
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
 
Algorithm & flow chart
Algorithm & flow chartAlgorithm & flow chart
Algorithm & flow chart
 
Algorithms & flowcharts
Algorithms & flowchartsAlgorithms & flowcharts
Algorithms & flowcharts
 
Csc 130 class 2 problem analysis and flow charts(2)
Csc 130 class 2   problem analysis and flow charts(2)Csc 130 class 2   problem analysis and flow charts(2)
Csc 130 class 2 problem analysis and flow charts(2)
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Algorithmsandflowcharts2
Algorithmsandflowcharts2Algorithmsandflowcharts2
Algorithmsandflowcharts2
 
Chapter 6 algorithms and flow charts
Chapter 6  algorithms and flow chartsChapter 6  algorithms and flow charts
Chapter 6 algorithms and flow charts
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Chapter 2 Representation Of Algorithms 2
Chapter 2  Representation Of  Algorithms 2Chapter 2  Representation Of  Algorithms 2
Chapter 2 Representation Of Algorithms 2
 
phases of algorithm
phases of algorithmphases of algorithm
phases of algorithm
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Flow chart
Flow chartFlow chart
Flow chart
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 

Similar to Programming fundamentals lecture 2 of c

Program design techniques
Program design techniquesProgram design techniques
Program design techniquesfika sweety
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1rajnidhiman
 
Algorithm Development
Algorithm DevelopmentAlgorithm Development
Algorithm DevelopmentALI RAZA
 
Best Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing TechniquesBest Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing TechniquesTech
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1Jesuraj Love
 
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTSALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTSKate Campbell
 
01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.ppt01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.pptFerdieBalang
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowchartskhair20
 
256958.ppt
256958.ppt256958.ppt
256958.pptBimlesh7
 
algorithms and flow chart overview.pdf
algorithms and flow chart overview.pdfalgorithms and flow chart overview.pdf
algorithms and flow chart overview.pdfAmanPratik11
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_progTAlha MAlik
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowchartsSamuel Igbanogu
 
if, while and for in Python
if, while and for in Pythonif, while and for in Python
if, while and for in PythonPranavSB
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialTo Sum It Up
 
Introduction to programming - class 2
Introduction to programming - class 2Introduction to programming - class 2
Introduction to programming - class 2Paul Brebner
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schoolsDan Bowen
 
Python language data types
Python language data typesPython language data types
Python language data typesHarry Potter
 

Similar to Programming fundamentals lecture 2 of c (20)

Program design techniques
Program design techniquesProgram design techniques
Program design techniques
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Algorithm Development
Algorithm DevelopmentAlgorithm Development
Algorithm Development
 
Best Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing TechniquesBest Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing Techniques
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTSALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
 
01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.ppt01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.ppt
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
 
256958.ppt
256958.ppt256958.ppt
256958.ppt
 
algorithms and flow chart overview.pdf
algorithms and flow chart overview.pdfalgorithms and flow chart overview.pdf
algorithms and flow chart overview.pdf
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_prog
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
 
if, while and for in Python
if, while and for in Pythonif, while and for in Python
if, while and for in Python
 
Cs 1114 - lecture-2
Cs 1114 - lecture-2Cs 1114 - lecture-2
Cs 1114 - lecture-2
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study material
 
Introduction to programming - class 2
Introduction to programming - class 2Introduction to programming - class 2
Introduction to programming - class 2
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schools
 
Python language data types
Python language data typesPython language data types
Python language data types
 

Programming fundamentals lecture 2 of c

  • 2. • Algorithm is the sequence of steps to be performed in order to solve a problem by the computer.
  • 3. Properties of Algorithm • The given problem should be broken down into simple and meaningful steps. • The step should be numbered sequentially. • The steps should be descriptive and written in simple English.
  • 4. Advantages of Algorithms • Reduce Complexity by dividing the program into simple and meaningful parts. • Increase Flexibility Algorithm is written so that the code may be written in any language. • Ease of Understanding No need to understand a particular programming language to understand an algorithm.
  • 5. How to write? • Pseudocode is an artificial and informal language that helps programmers to develop algorithms. – Pseudocode is very similar to everyday English. • Two Steps to write an algorithm:- – First produce a general algorithm (one can use pseudocode) – Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language.
  • 6. • Example 1: Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.
  • 7. Example Pseudocode: • Input a set of 4 marks • Calculate their average by summing and dividing by 4 • if average is below 50 Print “FAIL” else Print “PASS”
  • 8. • Detailed Algorithm • Step 1: Input M1,M2,M3,M4 Step 2: GRADE (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print “FAIL” else Print “PASS” endif
  • 9. • Write an algorithm to convert the length in feet to centimeter.
  • 10. Pseudocode: • Input the length in feet (Lft) • Calculate the length in cm (Lcm) by multiplying LFT with 30 • Print length in cm (LCM)
  • 11. Algorithm • Step 1: Input Lft • Step 2: Lcm Lft x 30 • Step 3: Print Lcm
  • 12. • Write an algorithm that will calculate the roots of a quadratic equation • Hint: d = sqrt (b2 4ac ), and the roots are: x1 = (–b + d)/2a and x2 = (–b – d)/2a
  • 13. Pseudocode: • Input the coefficients (a, b, c) of the quadratic equation • Calculate d • Calculate x1 • Calculate x2 • Print x1 and x2
  • 14. Algorithm: • Step 1: Input a, b, c • Step 2: d sqrt (b b 4 a c ) • Step 3: x1 (–b + d) / (2 x a) • Step 4: x2 (–b – d) / (2 x a) • Step 5: Print x1, x2
  • 15. Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message. ALGORITHM Step 1: Input VALUE1, VALUE2 Step 2: if (VALUE1 > VALUE2) then MAX VALUE1 else MAX VALUE2 endif Step 3: Print “The largest value is”, MAX
  • 16. Write an algorithm that reads three numbers and prints the value of the largest number. Step 1: Input N1, N2, N3 Step 2: if (N1>N2) then if (N1>N3) then MAX N1 [N1>N2, N1>N3] else MAX N3 [N3>N1>N2] endif else if (N2>N3) then MAX N2 [N2>N1, N2>N3] else MAX N3 [N3>N2>N1] endif endif Step 3: Print “The largest number is”, MAX
  • 17. Example Bonus Schedule OVERTIME – (2/3)*ABSENT Bonus Paid >40 hours $50 >30 but 40 hours $40 >20 but 30 hours $30 >10 but 20 hours $20 10 hours $10
  • 18. Step 1: Input NAME,OVERTIME,ABSENT • Step 2: if (OVERTIME–(2/3)*ABSENT > 40) then • PAYMENT 50 • else if (OVERTIME–(2/3)*ABSENT > 30) then • PAYMENT 40 • else if (OVERTIME–(2/3)*ABSENT > 20) then • PAYMENT 30 • else if (OVERTIME–(2/3)*ABSENT > 10) then • PAYMENT 20 • else • PAYMENT 10 • endif • Step 3: Print “Bonus for”, NAME “is $”, PAYMENT