SlideShare a Scribd company logo
Algorithm: The Fundamental knowledge needed to solve problems
using a computer is the notion of an algorithm.
“An Algorithm is a precise specification of a seq. of instructions
(tells what task is to be executed) to be carried out in order to solve a
given problem”.
Features of a good algorithm:
1.Finiteness: An algorithm must terminate after a finite number of steps
and further each step must be executable in finite amount of time
2.Definiteness (no ambiguity): Each steps of an algorithm must be precisely
defined; the action to be carried out must be rigorously and unambiguously
specified for each case.
3.Inputs/ Output: An algorithm has zero or more (but only finite), number
of inputs and (atleast 1)output.
4.Effectiveness(efficient): An algorithm should be effective. This means
that each of the operation to be performed in an algorithm must be
sufficiently basic that it can be done exactly and in a finite length of time.
Write an algorithm to add two numbers entered
by user.
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read (i/p)values num1 and num2.
Step 4: Add num1 and num2 and assign the result to
sum as: sum←num1+num2
Step 5: Display sum
Step 6: Stop
Flowchart: addition of 2 numbers
• Write an algorithm to find the largest among three different numbers
entered by user.
• Step 1: Start
• Step 2: Declare variables a,b and c.
• Step 3: Read variables a,b and c.
• Step 4: compare a & b:
• If a>b then
• {
• compare a & c:
• If a>c Then Display a is the largest number.
• Otherwise( if c>a) Then Display c is the largest number.
• }
• Otherwise(if b>a) then
• {
• compare b & c:
• If b>c Then Display b is the largest number.
• Otherwise(if c>a) Then Display c is the greatest number.
• }
• Step 5: Stop
Flowchart: largest among three different numbers
• Write an algorithm to find all roots of a quadratic
equation ax2
+bx+c=0.
• Step 1: Start
• Step 2: Declare variables a, b, c, D, r1, r2, real and
imaginary;
• Step 3: read a,b,c
• Step 4: Calculate discriminant as: D←b2
-4ac
• Step 5: Test discriminant and perform as:
• Step5.1: If D≥0 then do- r1←(-b+√D)/2a , r2←(-b-
√D)/2a ;then Display r1 and r2 as roots.
• Step5.2:Otherwise(Else) Calculate real part and
imaginary part as:
• real←b/2a, imaginary ←√(-D)/2a and Display
real +j(imaginary) and real -j(imaginary) as roots
• Step 6: Stop
Flowchart: roots of a quadratic equation ax2
+bx+c=0
• Write an algorithm to find the factorial of a number
entered by user.
• Step 1: Start
• Step 2: Declare variables n,factorial and i.
• Step 3: Initialize variables as factorial←1 and i←1
• Step 4: Read(i/p) value of n whose factorial is to be
calculated
• Step 5: Repeat the steps while i is smaller than n+1
• 5.1: multiply factorial by i and again store result in
factorial as: factorial←factorial*i
• 5.2: increase i by 1 as:i←i+1
• Step 6: Display last value stored in factorial
• Step 7: Stop
Flow chart: factorial of a number
• Write an algorithm to find the factorial of a
number entered by user.
• Step 1: Start
• Step 2: Declare variables n,factorial and i.
• Step 3: Initialize variables as factorial←1 and i←n
• Step 4: Read(i/p) value of n whose factorial is to
be calculated
• Step 5: Repeat the steps while i is not equal to 0
• 5.1: multiply factorial by i and again store
result in factorial as: factorial←factorial*i
• 5.2: decrease i by 1 as:i←i-1
• Step 6: Display last value stored in factorial
• Step 7: Stop
• Write an algorithm to check whether a number
entered by user is prime or not.
• Step 1: Start
• Step 2: Declare variables n,i,flag.
• Step 3: Initialize variables: flag←1 & i←2
• Step 4: Read n from user to be tested as prime or not.
• Step 5: Repeat the steps while i<(n/2)
• 5.1 If remainder of n%i equals 0
• then flag←0 & Go to step 6
• 5.2 otherwise increment i as:i←i+1
• Step 6: If flag=0 then write n is not prime
• otherwise write n is prime
• Step 7: Stop
Flow chart: To test whether a number is prime or not.
Write an algorithm to find the Fibonacci series till
term=1000.
Step 1: Start
Step 2: Declare variables first_term,second_term and
temp.
Step 3: Initialize variables first_term=0 & second_term=1
Step 4: Display first_term and second_term
Step 5: Repeat the steps while second_term<=1000
5.1: temp=second_term
5.2: second_term=second_term+first_term
5.3: first_term=temp
5.4: Display second_term
Step 6: Stop
Flow-Chart Fibonacci series till term=1000.
Write an algorithm to find sum of the digits of a number
(ex: num=452;sum of digits=4+5+2=>11)
Step 1: start
Step 2: declare variables num, sum,rem
Step 3: initialize sum=0 & i/p value of num
Step 4: Repeat steps while num is greater than 0 or not equal to 0
Step 4.1: To extract digit of unit place:divide num by 10 and save
its remainder in rem as: rem=num%10
Step 4.2: To remove digit of unit place our no. Is changed(it has 1
digit less):divide num by 10 and save its quotient in num again
as: num=num/10
Step 4.3: add rem with sum and again save it in sum as:
sum=sum+rem
Step 5: display sum
Step 6: stop
Flow-Chart: sum of the digits of a number

More Related Content

PDF
L- 14. 0 Algorithm_Flowchart_Example.pdf
PDF
Logic Development and Algorithm.
PPTX
Algorithm for computational problematic sit
PPTX
ALGO VS FLOW.pptx
PDF
Problem solving using Programming
PDF
Fundamental of Information Technology - UNIT 6
PPTX
PF-Lec 02(Algorithm FlowChart & Pseudocode).pptx
PPTX
Basic Algorithm @PPSC(1)
L- 14. 0 Algorithm_Flowchart_Example.pdf
Logic Development and Algorithm.
Algorithm for computational problematic sit
ALGO VS FLOW.pptx
Problem solving using Programming
Fundamental of Information Technology - UNIT 6
PF-Lec 02(Algorithm FlowChart & Pseudocode).pptx
Basic Algorithm @PPSC(1)

Similar to algorithm_practice.pptzkkxiqdhiwdowhdohwod2hodh2odh2o (20)

PPTX
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
PPTX
Flowchart and algorithm
PDF
ALGORITHMS AND FLOWCHARTS
PDF
Flowcharts. Algorithms and pseudo codepdf
PDF
4. algorithm
PPTX
Daa unit 1
PPT
DAA subject units powerpoint presentation classification of the university
PPT
DAA subject Power point presentations unit 1 Anna univer
PPT
Problem Solving Techniques notes for Unit 1
PPTX
Unit-1_PPS_H6nS4p8J1iooinoinoinoink.pptx
PPTX
Algorithm types performance steps working
PPTX
Unit 1(1).pptx Program Logic Development
PPTX
1. Problem Solving Techniques and Data Structures.pptx
PPTX
Flowchart and algorithem
PDF
Daa chapter 1
PPTX
Introduction to Design and Analysis of Algorithms
PPTX
Chapter #1 (Introduction To Algorithms).pptx
PPT
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
PPTX
design analysis of algorithmaa unit 1.pptx
PPT
UNIT-1-PPTS-DAA_INTRODUCTION_TO_DAA_GH.ppt
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
Flowchart and algorithm
ALGORITHMS AND FLOWCHARTS
Flowcharts. Algorithms and pseudo codepdf
4. algorithm
Daa unit 1
DAA subject units powerpoint presentation classification of the university
DAA subject Power point presentations unit 1 Anna univer
Problem Solving Techniques notes for Unit 1
Unit-1_PPS_H6nS4p8J1iooinoinoinoink.pptx
Algorithm types performance steps working
Unit 1(1).pptx Program Logic Development
1. Problem Solving Techniques and Data Structures.pptx
Flowchart and algorithem
Daa chapter 1
Introduction to Design and Analysis of Algorithms
Chapter #1 (Introduction To Algorithms).pptx
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
design analysis of algorithmaa unit 1.pptx
UNIT-1-PPTS-DAA_INTRODUCTION_TO_DAA_GH.ppt
Ad

Recently uploaded (20)

PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
advance database management system book.pdf
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Empowerment Technology for Senior High School Guide
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
1_English_Language_Set_2.pdf probationary
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
HVAC Specification 2024 according to central public works department
PPTX
Introduction to Building Materials
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
FORM 1 BIOLOGY MIND MAPS and their schemes
Share_Module_2_Power_conflict_and_negotiation.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Introduction to pro and eukaryotes and differences.pptx
advance database management system book.pdf
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
My India Quiz Book_20210205121199924.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
What if we spent less time fighting change, and more time building what’s rig...
Empowerment Technology for Senior High School Guide
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
B.Sc. DS Unit 2 Software Engineering.pptx
1_English_Language_Set_2.pdf probationary
Weekly quiz Compilation Jan -July 25.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
HVAC Specification 2024 according to central public works department
Introduction to Building Materials
TNA_Presentation-1-Final(SAVE)) (1).pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Ad

algorithm_practice.pptzkkxiqdhiwdowhdohwod2hodh2odh2o

  • 1. Algorithm: The Fundamental knowledge needed to solve problems using a computer is the notion of an algorithm. “An Algorithm is a precise specification of a seq. of instructions (tells what task is to be executed) to be carried out in order to solve a given problem”. Features of a good algorithm: 1.Finiteness: An algorithm must terminate after a finite number of steps and further each step must be executable in finite amount of time 2.Definiteness (no ambiguity): Each steps of an algorithm must be precisely defined; the action to be carried out must be rigorously and unambiguously specified for each case. 3.Inputs/ Output: An algorithm has zero or more (but only finite), number of inputs and (atleast 1)output. 4.Effectiveness(efficient): An algorithm should be effective. This means that each of the operation to be performed in an algorithm must be sufficiently basic that it can be done exactly and in a finite length of time.
  • 2. Write an algorithm to add two numbers entered by user. Step 1: Start Step 2: Declare variables num1, num2 and sum. Step 3: Read (i/p)values num1 and num2. Step 4: Add num1 and num2 and assign the result to sum as: sum←num1+num2 Step 5: Display sum Step 6: Stop
  • 4. • Write an algorithm to find the largest among three different numbers entered by user. • Step 1: Start • Step 2: Declare variables a,b and c. • Step 3: Read variables a,b and c. • Step 4: compare a & b: • If a>b then • { • compare a & c: • If a>c Then Display a is the largest number. • Otherwise( if c>a) Then Display c is the largest number. • } • Otherwise(if b>a) then • { • compare b & c: • If b>c Then Display b is the largest number. • Otherwise(if c>a) Then Display c is the greatest number. • } • Step 5: Stop
  • 5. Flowchart: largest among three different numbers
  • 6. • Write an algorithm to find all roots of a quadratic equation ax2 +bx+c=0. • Step 1: Start • Step 2: Declare variables a, b, c, D, r1, r2, real and imaginary; • Step 3: read a,b,c • Step 4: Calculate discriminant as: D←b2 -4ac • Step 5: Test discriminant and perform as: • Step5.1: If D≥0 then do- r1←(-b+√D)/2a , r2←(-b- √D)/2a ;then Display r1 and r2 as roots. • Step5.2:Otherwise(Else) Calculate real part and imaginary part as: • real←b/2a, imaginary ←√(-D)/2a and Display real +j(imaginary) and real -j(imaginary) as roots • Step 6: Stop
  • 7. Flowchart: roots of a quadratic equation ax2 +bx+c=0
  • 8. • Write an algorithm to find the factorial of a number entered by user. • Step 1: Start • Step 2: Declare variables n,factorial and i. • Step 3: Initialize variables as factorial←1 and i←1 • Step 4: Read(i/p) value of n whose factorial is to be calculated • Step 5: Repeat the steps while i is smaller than n+1 • 5.1: multiply factorial by i and again store result in factorial as: factorial←factorial*i • 5.2: increase i by 1 as:i←i+1 • Step 6: Display last value stored in factorial • Step 7: Stop
  • 9. Flow chart: factorial of a number
  • 10. • Write an algorithm to find the factorial of a number entered by user. • Step 1: Start • Step 2: Declare variables n,factorial and i. • Step 3: Initialize variables as factorial←1 and i←n • Step 4: Read(i/p) value of n whose factorial is to be calculated • Step 5: Repeat the steps while i is not equal to 0 • 5.1: multiply factorial by i and again store result in factorial as: factorial←factorial*i • 5.2: decrease i by 1 as:i←i-1 • Step 6: Display last value stored in factorial • Step 7: Stop
  • 11. • Write an algorithm to check whether a number entered by user is prime or not. • Step 1: Start • Step 2: Declare variables n,i,flag. • Step 3: Initialize variables: flag←1 & i←2 • Step 4: Read n from user to be tested as prime or not. • Step 5: Repeat the steps while i<(n/2) • 5.1 If remainder of n%i equals 0 • then flag←0 & Go to step 6 • 5.2 otherwise increment i as:i←i+1 • Step 6: If flag=0 then write n is not prime • otherwise write n is prime • Step 7: Stop
  • 12. Flow chart: To test whether a number is prime or not.
  • 13. Write an algorithm to find the Fibonacci series till term=1000. Step 1: Start Step 2: Declare variables first_term,second_term and temp. Step 3: Initialize variables first_term=0 & second_term=1 Step 4: Display first_term and second_term Step 5: Repeat the steps while second_term<=1000 5.1: temp=second_term 5.2: second_term=second_term+first_term 5.3: first_term=temp 5.4: Display second_term Step 6: Stop
  • 14. Flow-Chart Fibonacci series till term=1000.
  • 15. Write an algorithm to find sum of the digits of a number (ex: num=452;sum of digits=4+5+2=>11) Step 1: start Step 2: declare variables num, sum,rem Step 3: initialize sum=0 & i/p value of num Step 4: Repeat steps while num is greater than 0 or not equal to 0 Step 4.1: To extract digit of unit place:divide num by 10 and save its remainder in rem as: rem=num%10 Step 4.2: To remove digit of unit place our no. Is changed(it has 1 digit less):divide num by 10 and save its quotient in num again as: num=num/10 Step 4.3: add rem with sum and again save it in sum as: sum=sum+rem Step 5: display sum Step 6: stop
  • 16. Flow-Chart: sum of the digits of a number