SlideShare a Scribd company logo
1 of 11
for
Open Educational Resource
on
Logic Development and Programming (EC221)
by
Dr. Piyush Charan
Assistant Professor
Department of Electronics and Communication Engg.
Integral University, Lucknow
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Algorithm to reverse a Number
Input: 123
Output: 321
Step 1: Start
Step 2: Accept n
Step 3: [Initialize] rev=0
Step 4: Repeat steps 4 to 7 until n!=0
Step 5:rem=n%10
Step 6: rev=rev*10+rem
Step 7: n=n/10
Step 8: Display rev
Step 9: Stop
01/SEP/2020 2Dr. Piyush Charan, Dept. of ECE, IU Lucknow
Dry Run- Reverse a Number
n rem rev
123 3 0
12 2 3
1 1 32
0 321
For n=123
rem= 123%10=3
rem=12%10=2
rem=1%10=1
rev= 0×10+3=3
rev= 3×10+2=32
rev=32×10+1=321
n=123/10=12
n=12/10=1
n=1/10=0
01/SEP/2020 3Dr. Piyush Charan, Dept. of ECE, IU Lucknow
Input: 123
Output: 321
Algorithm to check for a
Palindrome Number
Step 1: Start
Step 2: Accept n
Step 3: [Initialize] rev=0, a=n
Step 4: Repeat steps 4 to 7 until n!=0
Step 5: rem=n%10
Step 6: rev=rev*10+rem
Step 7: n=n/10
Step 8: if rev==a
Step 9: print “It is a palindrome number”
Step 10: else print “It is not a palindrome number”
Step 11: Stop
01/SEP/2020 4Dr. Piyush Charan, Dept. of ECE, IU Lucknow
Dry Run- Reverse a Number
n a rem rev
121 121 1 0
12 2 1
1 1 12
0 121
For n=121
rem= 121%10=1
rem=12%10=2
rem=1%10=1
rev= 0×10+1=1
rev= 1×10+2=12
rev=12×10+1=121
n=121/10=12
n=12/10=1
n=1/10=0
01/SEP/2020 5Dr. Piyush Charan, Dept. of ECE, IU Lucknow
Input: 121
Output: It is a palindrome number
Algorithm to check Armstrong Number
Input: 153
Output: It is an Armstrong Number
Logic for Armstrong Numbers: 1^3+5^3+3^3=1+125+27=153
Step 1: Start
Step 2: Accept n
Step 3: [Initialize] sum=0, a=n
Step 4: Repeat steps 4 to 7 until n!=0
Step 5: rem=n%10
Step 6: sum=sum+ rem*rem*rem
Step 7: n=n/10
Step 8: Display sum
Step 9: if sum==a
Step 10: Print “It is an Armstrong Number”
Step 11: else Print “It is not an Armstrong Number”
Step 12: Stop
01/SEP/2020 6Dr. Piyush Charan, Dept. of ECE, IU Lucknow
Dry Run- Armstrong Number
n a rem sum
153 153 3 0
15 5 27
1 1 152
0 153
For n=153
rem= 153%10=3
rem=15%10=5
rem=1%10=1
sum= 0+3×3×3=27
sum= 27+5×5×5=152
sum=152+1×1×1=153
n=153/10=15
n=15/10=1
n=1/10=0
01/SEP/2020 7Dr. Piyush Charan, Dept. of ECE, IU Lucknow
Algorithm to generate Fibonacci
series using Iterative Logic
Step 1: Start
Step 2: Accept n
Step 3: Declare a, b, fib, i
Step 4: [Initialize] a=0, b=1, i=1
Step 5: Display a, b
Step 6: Repeat steps 6 to 11 until i<=n-2
Step 7: fib=a+b
Step 8: a=b
Step 9: b=fib
Step 10: Display fib
Step 11: i=i+1
Step 12: Stop
01/SEP/2020 Dr. Piyush Charan, Dept. of ECE, IU Lucknow 8
Dry Run- Fibonacci Series
up to ‘n’ terms
01/SEP/2020 Dr. Piyush Charan, Dept. of ECE, IU Lucknow 9
n a b fib i
4 0 1 1 1
1 1 2 2
1 2 3
For n=4
Output Window:
0 1 1 2
Algorithm to check whether a
number is Prime or not
Step 1: Start
Step 2: Accept n
Step 3: [Initialize] i=1, c=0
Step 4: Repeat steps 4 to 7 until i<=n
Step 5: if n%1==0 && n%i==0
Step 6: c=c+1
Step 7: i=i+1
Step 8: if c==2
Step 9: print “It is a Prime Number”
Step 10: else print “It is not a Prime Number”
Step 11: Stop
01/SEP/2020 Dr. Piyush Charan, Dept. of ECE, IU Lucknow 10
Dry Run- To check for
Prime Number
01/SEP/2020 Dr. Piyush Charan, Dept. of ECE, IU Lucknow 11
n i c
3 1 0
2 1
3 2
4
For n=3
Output Window:
It is a Prime Number
3%1==0 && 3%1==0
3%1==0 && 3%2!=0
3%1==0 && 3%3==0
 
 
 
Note: The counter ‘c’
increments only when
both the conditions are
TRUE together.

More Related Content

Similar to Unit 1 algorithms practise

Spm unit iii-risk-pert
Spm unit iii-risk-pertSpm unit iii-risk-pert
Spm unit iii-risk-pertKanchana Devi
 
4.9 cpm network calculations
4.9 cpm network calculations4.9 cpm network calculations
4.9 cpm network calculationsVishal Tidake
 
25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manualkamesh dagia
 
UNIT I_PSPP - Illustrative Problems (1).pptx
UNIT I_PSPP - Illustrative Problems (1).pptxUNIT I_PSPP - Illustrative Problems (1).pptx
UNIT I_PSPP - Illustrative Problems (1).pptxRSathyaPriyaCSEKIOT
 
7 Examples of C Program (Civil Engineering)
7 Examples of C Program (Civil Engineering)7 Examples of C Program (Civil Engineering)
7 Examples of C Program (Civil Engineering)Faisal F Rafat
 

Similar to Unit 1 algorithms practise (8)

Spm unit iii-risk-pert
Spm unit iii-risk-pertSpm unit iii-risk-pert
Spm unit iii-risk-pert
 
4.9 cpm network calculations
4.9 cpm network calculations4.9 cpm network calculations
4.9 cpm network calculations
 
25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual
 
Tugas Matematika 1
Tugas Matematika 1Tugas Matematika 1
Tugas Matematika 1
 
UNIT I_PSPP - Illustrative Problems (1).pptx
UNIT I_PSPP - Illustrative Problems (1).pptxUNIT I_PSPP - Illustrative Problems (1).pptx
UNIT I_PSPP - Illustrative Problems (1).pptx
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
7 Examples of C Program (Civil Engineering)
7 Examples of C Program (Civil Engineering)7 Examples of C Program (Civil Engineering)
7 Examples of C Program (Civil Engineering)
 
Composite Performance Index for Student Admission
Composite Performance Index for Student AdmissionComposite Performance Index for Student Admission
Composite Performance Index for Student Admission
 

More from Dr Piyush Charan

Unit 1- Intro to Wireless Standards.pdf
Unit 1- Intro to Wireless Standards.pdfUnit 1- Intro to Wireless Standards.pdf
Unit 1- Intro to Wireless Standards.pdfDr Piyush Charan
 
Unit 4 Lossy Coding Preliminaries
Unit 4 Lossy Coding PreliminariesUnit 4 Lossy Coding Preliminaries
Unit 4 Lossy Coding PreliminariesDr Piyush Charan
 
Unit 2: Programming Language Tools
Unit 2:  Programming Language ToolsUnit 2:  Programming Language Tools
Unit 2: Programming Language ToolsDr Piyush Charan
 
Unit 3 Lecture Notes on Programming
Unit 3 Lecture Notes on ProgrammingUnit 3 Lecture Notes on Programming
Unit 3 Lecture Notes on ProgrammingDr Piyush Charan
 
Unit 3 introduction to programming
Unit 3 introduction to programmingUnit 3 introduction to programming
Unit 3 introduction to programmingDr Piyush Charan
 
Forensics and wireless body area networks
Forensics and wireless body area networksForensics and wireless body area networks
Forensics and wireless body area networksDr Piyush Charan
 
Final PhD Defense Presentation
Final PhD Defense PresentationFinal PhD Defense Presentation
Final PhD Defense PresentationDr Piyush Charan
 
Unit 2 Lecture notes on Huffman coding
Unit 2 Lecture notes on Huffman codingUnit 2 Lecture notes on Huffman coding
Unit 2 Lecture notes on Huffman codingDr Piyush Charan
 
Unit 1 Introduction to Data Compression
Unit 1 Introduction to Data CompressionUnit 1 Introduction to Data Compression
Unit 1 Introduction to Data CompressionDr Piyush Charan
 
Unit 3 Dictionary based Compression Techniques
Unit 3 Dictionary based Compression TechniquesUnit 3 Dictionary based Compression Techniques
Unit 3 Dictionary based Compression TechniquesDr Piyush Charan
 
Unit 1 Introduction to Non-Conventional Energy Resources
Unit 1 Introduction to Non-Conventional Energy ResourcesUnit 1 Introduction to Non-Conventional Energy Resources
Unit 1 Introduction to Non-Conventional Energy ResourcesDr Piyush Charan
 
Unit 5-Operational Amplifiers and Electronic Measurement Devices
Unit 5-Operational Amplifiers and Electronic Measurement DevicesUnit 5-Operational Amplifiers and Electronic Measurement Devices
Unit 5-Operational Amplifiers and Electronic Measurement DevicesDr Piyush Charan
 
Unit 1 Introduction to Data Compression
Unit 1 Introduction to Data CompressionUnit 1 Introduction to Data Compression
Unit 1 Introduction to Data CompressionDr Piyush Charan
 
Unit 4 Switching Theory and Logic Gates
Unit 4 Switching Theory and Logic GatesUnit 4 Switching Theory and Logic Gates
Unit 4 Switching Theory and Logic GatesDr Piyush Charan
 
Unit 1 Numerical Problems on PN Junction Diode
Unit 1 Numerical Problems on PN Junction DiodeUnit 1 Numerical Problems on PN Junction Diode
Unit 1 Numerical Problems on PN Junction DiodeDr Piyush Charan
 

More from Dr Piyush Charan (20)

Unit 1- Intro to Wireless Standards.pdf
Unit 1- Intro to Wireless Standards.pdfUnit 1- Intro to Wireless Standards.pdf
Unit 1- Intro to Wireless Standards.pdf
 
Unit 1 Solar Collectors
Unit 1 Solar CollectorsUnit 1 Solar Collectors
Unit 1 Solar Collectors
 
Unit 5 Quantization
Unit 5 QuantizationUnit 5 Quantization
Unit 5 Quantization
 
Unit 4 Lossy Coding Preliminaries
Unit 4 Lossy Coding PreliminariesUnit 4 Lossy Coding Preliminaries
Unit 4 Lossy Coding Preliminaries
 
Unit 3 Geothermal Energy
Unit 3 Geothermal EnergyUnit 3 Geothermal Energy
Unit 3 Geothermal Energy
 
Unit 2: Programming Language Tools
Unit 2:  Programming Language ToolsUnit 2:  Programming Language Tools
Unit 2: Programming Language Tools
 
Unit 4 Arrays
Unit 4 ArraysUnit 4 Arrays
Unit 4 Arrays
 
Unit 3 Lecture Notes on Programming
Unit 3 Lecture Notes on ProgrammingUnit 3 Lecture Notes on Programming
Unit 3 Lecture Notes on Programming
 
Unit 3 introduction to programming
Unit 3 introduction to programmingUnit 3 introduction to programming
Unit 3 introduction to programming
 
Forensics and wireless body area networks
Forensics and wireless body area networksForensics and wireless body area networks
Forensics and wireless body area networks
 
Final PhD Defense Presentation
Final PhD Defense PresentationFinal PhD Defense Presentation
Final PhD Defense Presentation
 
Unit 3 Arithmetic Coding
Unit 3 Arithmetic CodingUnit 3 Arithmetic Coding
Unit 3 Arithmetic Coding
 
Unit 2 Lecture notes on Huffman coding
Unit 2 Lecture notes on Huffman codingUnit 2 Lecture notes on Huffman coding
Unit 2 Lecture notes on Huffman coding
 
Unit 1 Introduction to Data Compression
Unit 1 Introduction to Data CompressionUnit 1 Introduction to Data Compression
Unit 1 Introduction to Data Compression
 
Unit 3 Dictionary based Compression Techniques
Unit 3 Dictionary based Compression TechniquesUnit 3 Dictionary based Compression Techniques
Unit 3 Dictionary based Compression Techniques
 
Unit 1 Introduction to Non-Conventional Energy Resources
Unit 1 Introduction to Non-Conventional Energy ResourcesUnit 1 Introduction to Non-Conventional Energy Resources
Unit 1 Introduction to Non-Conventional Energy Resources
 
Unit 5-Operational Amplifiers and Electronic Measurement Devices
Unit 5-Operational Amplifiers and Electronic Measurement DevicesUnit 5-Operational Amplifiers and Electronic Measurement Devices
Unit 5-Operational Amplifiers and Electronic Measurement Devices
 
Unit 1 Introduction to Data Compression
Unit 1 Introduction to Data CompressionUnit 1 Introduction to Data Compression
Unit 1 Introduction to Data Compression
 
Unit 4 Switching Theory and Logic Gates
Unit 4 Switching Theory and Logic GatesUnit 4 Switching Theory and Logic Gates
Unit 4 Switching Theory and Logic Gates
 
Unit 1 Numerical Problems on PN Junction Diode
Unit 1 Numerical Problems on PN Junction DiodeUnit 1 Numerical Problems on PN Junction Diode
Unit 1 Numerical Problems on PN Junction Diode
 

Recently uploaded

(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 

Recently uploaded (20)

(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 

Unit 1 algorithms practise

  • 1. for Open Educational Resource on Logic Development and Programming (EC221) by Dr. Piyush Charan Assistant Professor Department of Electronics and Communication Engg. Integral University, Lucknow This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
  • 2. Algorithm to reverse a Number Input: 123 Output: 321 Step 1: Start Step 2: Accept n Step 3: [Initialize] rev=0 Step 4: Repeat steps 4 to 7 until n!=0 Step 5:rem=n%10 Step 6: rev=rev*10+rem Step 7: n=n/10 Step 8: Display rev Step 9: Stop 01/SEP/2020 2Dr. Piyush Charan, Dept. of ECE, IU Lucknow
  • 3. Dry Run- Reverse a Number n rem rev 123 3 0 12 2 3 1 1 32 0 321 For n=123 rem= 123%10=3 rem=12%10=2 rem=1%10=1 rev= 0×10+3=3 rev= 3×10+2=32 rev=32×10+1=321 n=123/10=12 n=12/10=1 n=1/10=0 01/SEP/2020 3Dr. Piyush Charan, Dept. of ECE, IU Lucknow Input: 123 Output: 321
  • 4. Algorithm to check for a Palindrome Number Step 1: Start Step 2: Accept n Step 3: [Initialize] rev=0, a=n Step 4: Repeat steps 4 to 7 until n!=0 Step 5: rem=n%10 Step 6: rev=rev*10+rem Step 7: n=n/10 Step 8: if rev==a Step 9: print “It is a palindrome number” Step 10: else print “It is not a palindrome number” Step 11: Stop 01/SEP/2020 4Dr. Piyush Charan, Dept. of ECE, IU Lucknow
  • 5. Dry Run- Reverse a Number n a rem rev 121 121 1 0 12 2 1 1 1 12 0 121 For n=121 rem= 121%10=1 rem=12%10=2 rem=1%10=1 rev= 0×10+1=1 rev= 1×10+2=12 rev=12×10+1=121 n=121/10=12 n=12/10=1 n=1/10=0 01/SEP/2020 5Dr. Piyush Charan, Dept. of ECE, IU Lucknow Input: 121 Output: It is a palindrome number
  • 6. Algorithm to check Armstrong Number Input: 153 Output: It is an Armstrong Number Logic for Armstrong Numbers: 1^3+5^3+3^3=1+125+27=153 Step 1: Start Step 2: Accept n Step 3: [Initialize] sum=0, a=n Step 4: Repeat steps 4 to 7 until n!=0 Step 5: rem=n%10 Step 6: sum=sum+ rem*rem*rem Step 7: n=n/10 Step 8: Display sum Step 9: if sum==a Step 10: Print “It is an Armstrong Number” Step 11: else Print “It is not an Armstrong Number” Step 12: Stop 01/SEP/2020 6Dr. Piyush Charan, Dept. of ECE, IU Lucknow
  • 7. Dry Run- Armstrong Number n a rem sum 153 153 3 0 15 5 27 1 1 152 0 153 For n=153 rem= 153%10=3 rem=15%10=5 rem=1%10=1 sum= 0+3×3×3=27 sum= 27+5×5×5=152 sum=152+1×1×1=153 n=153/10=15 n=15/10=1 n=1/10=0 01/SEP/2020 7Dr. Piyush Charan, Dept. of ECE, IU Lucknow
  • 8. Algorithm to generate Fibonacci series using Iterative Logic Step 1: Start Step 2: Accept n Step 3: Declare a, b, fib, i Step 4: [Initialize] a=0, b=1, i=1 Step 5: Display a, b Step 6: Repeat steps 6 to 11 until i<=n-2 Step 7: fib=a+b Step 8: a=b Step 9: b=fib Step 10: Display fib Step 11: i=i+1 Step 12: Stop 01/SEP/2020 Dr. Piyush Charan, Dept. of ECE, IU Lucknow 8
  • 9. Dry Run- Fibonacci Series up to ‘n’ terms 01/SEP/2020 Dr. Piyush Charan, Dept. of ECE, IU Lucknow 9 n a b fib i 4 0 1 1 1 1 1 2 2 1 2 3 For n=4 Output Window: 0 1 1 2
  • 10. Algorithm to check whether a number is Prime or not Step 1: Start Step 2: Accept n Step 3: [Initialize] i=1, c=0 Step 4: Repeat steps 4 to 7 until i<=n Step 5: if n%1==0 && n%i==0 Step 6: c=c+1 Step 7: i=i+1 Step 8: if c==2 Step 9: print “It is a Prime Number” Step 10: else print “It is not a Prime Number” Step 11: Stop 01/SEP/2020 Dr. Piyush Charan, Dept. of ECE, IU Lucknow 10
  • 11. Dry Run- To check for Prime Number 01/SEP/2020 Dr. Piyush Charan, Dept. of ECE, IU Lucknow 11 n i c 3 1 0 2 1 3 2 4 For n=3 Output Window: It is a Prime Number 3%1==0 && 3%1==0 3%1==0 && 3%2!=0 3%1==0 && 3%3==0       Note: The counter ‘c’ increments only when both the conditions are TRUE together.