SlideShare a Scribd company logo
1 of 20
Download to read offline
Problem Solving
Dr. Kuppusamy .P
Associate Professor / SCOPE
Dr. Kuppusamy P
Problem Statement 1: Design an algorithm and
draw the flow chart to exchange two values.
• Let’s consider two glasses denoted A and B with 30 ml
mango juice and 50 ml orange juice. Find out the way to
exchange the juice in A and B.
Dr. Kuppusamy P
• Declare variables
• Initialize the values
Problem Statement 1: Design an algorithm and
draw the flow chart to exchange two values.
Dr. Kuppusamy P
Problem Statement 1: Design an algorithm and
draw the flow chart to exchange two values.
Move Glass A value 30 to Glass
Temp
Move Glass B value 50 to
Glass A
Dr. Kuppusamy P
Problem Statement 1: Design an algorithm and
draw the flow chart to exchange two values.
Move Glass Temp value 30 to
Glass B
Dr. Kuppusamy P
Problem Statement 1: Design an algorithm and
draw the flow chart to exchange two values.
Algorithm
Step 1. Start
Step 2. Declare two variables A, B and one more variable temp
Step 3. Read the positive numbers to A and B
Step 3. temp ← A
Step 4. A ← B
Step 5. B ← temp
Step 6. Display interchanged numbers in A , B
Step 7. Stop
Dr. Kuppusamy P
Problem Statement 1: Design an algorithm and
draw the flow chart to exchange two values.
Algorithm
Step 1. Start
Step 2. Declare two variables A, B and one more variable temp
Step 3. Read the positive numbers to A and B
Step 3. temp ← A
Step 4. A ← B
Step 5. B ← temp
Step 6. Display interchanged numbers in A , B
Step 7. Stop
Read the positive
numbers to A and B
temp ← A
A ← B
B ← temp
Display
interchanged
numbers in A , B
Stop
Start
Declare variables A, B,
temp
Dr. Kuppusamy P
Problem Statement 2: Design an algorithm
and draw the flow chart to exchange two
values without using temporary variable.
Algorithm
Step 1. Start
Step 2. Declare two variables A, B
Step 3. Read the positive numbers as A and B
Step 3. A ← A + B
Step 4. B ← A - B
Step 5. A ← A - B
Step 6. Display interchanged numbers in A , B
Step 7. Stop
E.g. A = 7, B= 5
A = 7 + 5 =12
B = 12-5 =7
A= 12 - 7 =5
Dr. Kuppusamy P
Problem Statement 2: Design an algorithm
and draw the flow chart to exchange two
values without using temporary variable.
Algorithm
Step 1. Start
Step 2. Declare two variables A, B
Step 3. Read the positive numbers as A and B
Step 3. A ← A + B
Step 4. B ← A - B
Step 5. A ← A - B
Step 6. Display interchanged numbers in A , B
Step 7. Stop
E.g. A = 7, B= 5
A = 7 + 5 =12
B = 12-5 =7
A= 12 - 7 =5
Read the positive
numbers to A and B
A ← A + B
B ← A - B
A ← A - B
Display
interchanged
numbers in A , B
Stop
Start
Declare variables A, B
Dr. Kuppusamy P
Problem Statement 3: Design an algorithm and draw
the flow chart to find the sum of individual digits for
the given non negative integer.
Step 1. Start
Step 2. Declare variable n
Step 3. Read non negative integer (n)
Step 4. Initialize result ← 0
Step 5. Repeat until n > 0
Step 5.1 result ← result + (n % 10)
Step 5.2 n ← n / 10
Step 6. Display result
Step 7. Stop
E.g. Iteration: 1
n = 76
result = 0 + (76 % 10)
n = 76/10
Iteration: 2
n = 7
result = 6 + (7 % 10)
n = 7/10
Dr. Kuppusamy P
Repeat
Yes No
Problem Statement 3: Design an algorithm and draw
the flow chart to find the sum of individual digits for
the given non negative integer.
Step 1. Start
Step 2. Declare variable n
Step 3. Read non negative integer (n)
Step 4. Initialize result ← 0
Step 5. Repeat until n > 0
Step 5.1 result ← result + (n % 10)
Step 5.2 n ← n / 10
Step 6. Display result
Step 7. Stop
Read the positive
number n
result ← result + (n % 10)
n ← n / 10
Display the result
Stop
Start
Declare variable n
Repeat until n >0
Dr. Kuppusamy P
Problem Statement 4: Design an algorithm and draw
the flow chart to find the sum of given set of n positive
integer.
Step 1. Start
Step 2. Declare variables n, sum, a, i
Step 3. Read total numbers value (n) and ‘n’ positive integers in array ‘a’
Step 4. Initialize sum ← 0 , i ← 0
Step 5. Repeat until i < n
Step 5.1 sum ← sum + a[i]
Step 5.2 i ← i + 1
Step 6. Display sum
Step 7. Stop
n = 3
a[] = {2, 3, 4}
sum = 0 , i=0
Iteration: 1
sum = 0 + 2
i = i +1
Iteration: 2
sum = 2 + 3
i = i +1
Iteration: 3
sum = 5 + 4
i = i +1
Dr. Kuppusamy P
Problem Statement 4: Design an algorithm and draw
the flow chart to find the sum of given set of n positive
integer.
Step 1. Start
Step 2. Declare variables n, sum, a
Step 3. Read total numbers value (n)
and ‘n’ positive integers in
array ‘a’
Step 4. Initialize sum ← 0, i ← 0,
Step 5. Repeat until i < n
Step 5.1 sum ← sum + a[i]
Step 5.2 i ← i + 1
Step 6. Display sum
Step 7. Stop
Repeat
Yes No
Read total numbers value (n)
and ‘n’ integers in array ‘a’
sum ← sum + a[i]
i ← i + 1
Display the sum
Stop
Start
Declare variable n, sum, a
Repeat until i <n
Dr. Kuppusamy P
Problem Statement 5: Design an algorithm and draw
the flow chart to find the number of digits in given
number
Sample Input 1: 4582
Sample Output 1: The number of digits in 4582 is 4
Algorithm
Step 1. Start
Step 2. Declare variables
Step 3. Read the input
Step 4. Initialize count ← 0
Step 4. Repeat until n !=0
Step 5.1 count ← count + 1
Step 5.2 n ← n / 10
Step 6. Display count
Step 7. End
Iteration: 1
count = 0 + 1
n= 4582 /10
Iteration: 2
count = 1 + 1
n= 458 /10
Iteration: 3
count = 2 + 1
n= 45 /10
Iteration: 4
count = 3 + 1
n= 4 /10
Iteration: 5
n != 0 → False
Dr. Kuppusamy P
Problem Statement 6: Design an algorithm and draw
the flow chart to find Factorial computation
of given number
Sample Input 1: 4!
Sample Output 1: 24
Step 1. Begin
Step 2. Declare variables
Step 3. Read the decimal number n
Step 4. Initialize fact ← 1, i ← 1
Step 4. if (n != 0)
Step 4.1. Repeat until 1 to n
Step 4.1.1 fact ← fact * i
Step 4.1.2 increment i
Step 5. Display fact
Step 7. End
Iteration: 1
fact = 1 * 1
i = i +1
Iteration: 2
fact = 1 * 2
i = i +1
Iteration: 3
fact = 2 *3
i = i +1
Iteration: 4
fact = 6 * 4
i = i +1
Iteration: 5
i < =n → False
Dr. Kuppusamy P
Problem Statement 7: Design an algorithm and draw
the flow chart to find Sine function computation
Step 1. Begin.
Step 2. Read the input x and n
Step 3. Convert x value to radius using rad ← 3.14/180*x.
Step 4. Initialize sum ← rad, sign ← -1.
Step 5. Repeat for i ← 3 to n in increment by 2.
Step 5.1 power ← pow(rad, i).
Step 5.2 factorial ← factorial*(i-1)*i.
Step 5.3 result ← power / factorial.
Step 5.4 sum ← sum + (sign * result).
Step 5.5 k ← k*(-1).
Step 6. Display the sum as sine series result.
Step 7. End.
Dr. Kuppusamy P
Repeat
Yes No
Read the input x and n
power ← pow(rad, i).
factorial ← factorial*(i-1)*i.
result ← power / factorial.
sum ← sum + (sign * result).
k ← k*(-1)
Display the sum
Stop
Start
Declare variable
Repeat until i <n
Initialize sum, sign
Problem Statement 8: Design an algorithm and draw
the flow chart to generate Fibonacci sequence
Step 1. Begin
Step 2. Get Non-negative decimal limit n
Step 3. Initialize num1 ← 0, num2 ← 1
Step 4. Display num1 and num2
Step 5. Repeat until 1 to n- 2
Step 5.1 num3 ← num1 + num2
Step 5.2 Display num3
Step 5.3 num1 ← num2
Step 5.4 num2 ← num3
Step 6. End
Dr. Kuppusamy P
Input : 5
Output: 0, 1, 1, 2, 3, 5
Problem Statement 9: Design an algorithm and draw
the flow chart to Reverse the digits of an integer
Step 1. Begin
Step 2. Get Non-negative integer num
Step 3. Initialize reversed ← 0
Step 4. Repeat until num > 0
Step 4.1 digit ← n % 10
Step 4.2 reversed ← (reversed * 10) + digit;
Step 4.3 num ← num / 10
Step 5. Display reversed
Step 6. End
Dr. Kuppusamy P
Input : 598
Output: 895
Problem Statement 10: Design an algorithm and draw the flow chart to
Decimal to Binary conversion
Step 1. Begin
Step 2. Get a Positive decimal number (n)
Step 3. Initialize result as null
Step 4. if (n > 1)
Step 4.1. Repeat until n < 2
Step 4.1.1 Remainder ← n % 2
Step 4.1.2 Append remainder with result
Step 4.1.3 n ← n / 2
Step 5. Append n with result
Step 6. Display the reverse of result
Step 7. End
Dr. Kuppusamy P
Input : 3
Output: 011
Repeat
Yes No
Read integer n
Remainder ← n % 2
Append remainder with result
n ← n / 2
Append n with result
Display the reverse of
result
Stop
Start
Declare variable
Initialize result as null
Repeat until n<2
References
Dr. Kuppusamy P
• Herbert Schildt, “Java: The Complete Reference”, McGraw-Hill Education, Tenth
edition, 2017.
• https://www.sitesbay.com

More Related Content

What's hot

Unit 1 program development cycle
Unit 1 program development cycleUnit 1 program development cycle
Unit 1 program development cycleDhana malar
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
 
Algorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodesAlgorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodesSatveer Mann
 
Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Raja Hamid
 
Chapter 7 basics of computational thinking
Chapter 7 basics of computational thinkingChapter 7 basics of computational thinking
Chapter 7 basics of computational thinkingPraveen M Jigajinni
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsMohamed Loey
 
Flowcharts and algorithms
Flowcharts and algorithmsFlowcharts and algorithms
Flowcharts and algorithmsStudent
 
2.1.1 PROBLEM SOLVING & DESIGN
2.1.1 PROBLEM SOLVING & DESIGN2.1.1 PROBLEM SOLVING & DESIGN
2.1.1 PROBLEM SOLVING & DESIGNBuxoo Abdullah
 
10. switch case
10. switch case10. switch case
10. switch caseWay2itech
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer Ashim Lamichhane
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codeshermiraguilar
 
introduction to c language
 introduction to c language introduction to c language
introduction to c languageRai University
 
Lesson 1: Scratch Computer Programming
Lesson 1: Scratch Computer ProgrammingLesson 1: Scratch Computer Programming
Lesson 1: Scratch Computer ProgrammingSeniorInfants
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIMohamed Loey
 
Algorithm and flowchart
Algorithm and flowchart Algorithm and flowchart
Algorithm and flowchart Shivam Sharma
 

What's hot (20)

Unit 1 program development cycle
Unit 1 program development cycleUnit 1 program development cycle
Unit 1 program development cycle
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Algorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodesAlgorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodes
 
Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2
 
Chapter 7 basics of computational thinking
Chapter 7 basics of computational thinkingChapter 7 basics of computational thinking
Chapter 7 basics of computational thinking
 
History of c
History of cHistory of c
History of c
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Flowcharts and algorithms
Flowcharts and algorithmsFlowcharts and algorithms
Flowcharts and algorithms
 
2.1.1 PROBLEM SOLVING & DESIGN
2.1.1 PROBLEM SOLVING & DESIGN2.1.1 PROBLEM SOLVING & DESIGN
2.1.1 PROBLEM SOLVING & DESIGN
 
10. switch case
10. switch case10. switch case
10. switch case
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Problem solving methodology
Problem solving methodologyProblem solving methodology
Problem solving methodology
 
Problem solving and design
Problem solving and designProblem solving and design
Problem solving and design
 
introduction to c language
 introduction to c language introduction to c language
introduction to c language
 
Lesson 1: Scratch Computer Programming
Lesson 1: Scratch Computer ProgrammingLesson 1: Scratch Computer Programming
Lesson 1: Scratch Computer Programming
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms II
 
Algorithm and flowchart
Algorithm and flowchart Algorithm and flowchart
Algorithm and flowchart
 

Similar to Problem solving using Programming

UNIT I - Algorithmic Problem Solving.pptx
UNIT I - Algorithmic Problem Solving.pptxUNIT I - Algorithmic Problem Solving.pptx
UNIT I - Algorithmic Problem Solving.pptxPradeepkumar964266
 
Two step equations
Two step equationsTwo step equations
Two step equationsdevsmith07
 
Chapter2.8
Chapter2.8Chapter2.8
Chapter2.8nglaze10
 
Algorithmsandflowcharts2
Algorithmsandflowcharts2Algorithmsandflowcharts2
Algorithmsandflowcharts2Darlene Interno
 
New ways of multiplying numbers
New ways of multiplying numbersNew ways of multiplying numbers
New ways of multiplying numbersiosrjce
 
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
 
Multiplying Decimals
Multiplying DecimalsMultiplying Decimals
Multiplying DecimalsLea Perez
 
Chapter 3 - Problem Solving.pdf
Chapter 3 - Problem Solving.pdfChapter 3 - Problem Solving.pdf
Chapter 3 - Problem Solving.pdfMinaSaflor
 
Chapter1.4
Chapter1.4Chapter1.4
Chapter1.4nglaze10
 
Algebra 1 week 8 learn it 1
Algebra 1 week 8 learn it 1Algebra 1 week 8 learn it 1
Algebra 1 week 8 learn it 1JessicaBiemiller
 
Solving One Step Equations
Solving One Step Equations Solving One Step Equations
Solving One Step Equations Kelly Williams
 
Stanford splash spring 2016 basic programming
Stanford splash spring 2016 basic programmingStanford splash spring 2016 basic programming
Stanford splash spring 2016 basic programmingYu-Sheng (Yosen) Chen
 
Chapter2.6
Chapter2.6Chapter2.6
Chapter2.6nglaze10
 

Similar to Problem solving using Programming (20)

UNIT I - Algorithmic Problem Solving.pptx
UNIT I - Algorithmic Problem Solving.pptxUNIT I - Algorithmic Problem Solving.pptx
UNIT I - Algorithmic Problem Solving.pptx
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Lecture 7.pptx
Lecture 7.pptxLecture 7.pptx
Lecture 7.pptx
 
Two step equations
Two step equationsTwo step equations
Two step equations
 
Chapter2.8
Chapter2.8Chapter2.8
Chapter2.8
 
Algorithmsandflowcharts2
Algorithmsandflowcharts2Algorithmsandflowcharts2
Algorithmsandflowcharts2
 
Computer basics
Computer basicsComputer basics
Computer basics
 
New ways of multiplying numbers
New ways of multiplying numbersNew ways of multiplying numbers
New ways of multiplying numbers
 
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
 
PSP LAB MANUAL.pdf
PSP LAB MANUAL.pdfPSP LAB MANUAL.pdf
PSP LAB MANUAL.pdf
 
Module 1 topic 1 notes
Module 1 topic 1 notesModule 1 topic 1 notes
Module 1 topic 1 notes
 
Multiplying Decimals
Multiplying DecimalsMultiplying Decimals
Multiplying Decimals
 
Whole Numbers std 6.ppt
Whole Numbers std 6.pptWhole Numbers std 6.ppt
Whole Numbers std 6.ppt
 
Chapter 3 - Problem Solving.pdf
Chapter 3 - Problem Solving.pdfChapter 3 - Problem Solving.pdf
Chapter 3 - Problem Solving.pdf
 
Chapter1.4
Chapter1.4Chapter1.4
Chapter1.4
 
ppt math6 qt3-wk3.pptx
ppt math6 qt3-wk3.pptxppt math6 qt3-wk3.pptx
ppt math6 qt3-wk3.pptx
 
Algebra 1 week 8 learn it 1
Algebra 1 week 8 learn it 1Algebra 1 week 8 learn it 1
Algebra 1 week 8 learn it 1
 
Solving One Step Equations
Solving One Step Equations Solving One Step Equations
Solving One Step Equations
 
Stanford splash spring 2016 basic programming
Stanford splash spring 2016 basic programmingStanford splash spring 2016 basic programming
Stanford splash spring 2016 basic programming
 
Chapter2.6
Chapter2.6Chapter2.6
Chapter2.6
 

More from Kuppusamy P

Recurrent neural networks rnn
Recurrent neural networks   rnnRecurrent neural networks   rnn
Recurrent neural networks rnnKuppusamy P
 
Image segmentation
Image segmentationImage segmentation
Image segmentationKuppusamy P
 
Image enhancement
Image enhancementImage enhancement
Image enhancementKuppusamy P
 
Feature detection and matching
Feature detection and matchingFeature detection and matching
Feature detection and matchingKuppusamy P
 
Image processing, Noise, Noise Removal filters
Image processing, Noise, Noise Removal filtersImage processing, Noise, Noise Removal filters
Image processing, Noise, Noise Removal filtersKuppusamy P
 
Flowchart design for algorithms
Flowchart design for algorithmsFlowchart design for algorithms
Flowchart design for algorithmsKuppusamy P
 
Algorithm basics
Algorithm basicsAlgorithm basics
Algorithm basicsKuppusamy P
 
Parts of Computer, Hardware and Software
Parts of Computer, Hardware and Software Parts of Computer, Hardware and Software
Parts of Computer, Hardware and Software Kuppusamy P
 
Java methods or Subroutines or Functions
Java methods or Subroutines or FunctionsJava methods or Subroutines or Functions
Java methods or Subroutines or FunctionsKuppusamy P
 
Java iterative statements
Java iterative statementsJava iterative statements
Java iterative statementsKuppusamy P
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statementsKuppusamy P
 
Java introduction
Java introductionJava introduction
Java introductionKuppusamy P
 
Logistic regression in Machine Learning
Logistic regression in Machine LearningLogistic regression in Machine Learning
Logistic regression in Machine LearningKuppusamy P
 
Anomaly detection (Unsupervised Learning) in Machine Learning
Anomaly detection (Unsupervised Learning) in Machine LearningAnomaly detection (Unsupervised Learning) in Machine Learning
Anomaly detection (Unsupervised Learning) in Machine LearningKuppusamy P
 
Machine Learning Performance metrics for classification
Machine Learning Performance metrics for classificationMachine Learning Performance metrics for classification
Machine Learning Performance metrics for classificationKuppusamy P
 
Machine learning Introduction
Machine learning IntroductionMachine learning Introduction
Machine learning IntroductionKuppusamy P
 

More from Kuppusamy P (20)

Recurrent neural networks rnn
Recurrent neural networks   rnnRecurrent neural networks   rnn
Recurrent neural networks rnn
 
Deep learning
Deep learningDeep learning
Deep learning
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
Image enhancement
Image enhancementImage enhancement
Image enhancement
 
Feature detection and matching
Feature detection and matchingFeature detection and matching
Feature detection and matching
 
Image processing, Noise, Noise Removal filters
Image processing, Noise, Noise Removal filtersImage processing, Noise, Noise Removal filters
Image processing, Noise, Noise Removal filters
 
Flowchart design for algorithms
Flowchart design for algorithmsFlowchart design for algorithms
Flowchart design for algorithms
 
Algorithm basics
Algorithm basicsAlgorithm basics
Algorithm basics
 
Parts of Computer, Hardware and Software
Parts of Computer, Hardware and Software Parts of Computer, Hardware and Software
Parts of Computer, Hardware and Software
 
Strings in java
Strings in javaStrings in java
Strings in java
 
Java methods or Subroutines or Functions
Java methods or Subroutines or FunctionsJava methods or Subroutines or Functions
Java methods or Subroutines or Functions
 
Java arrays
Java arraysJava arrays
Java arrays
 
Java iterative statements
Java iterative statementsJava iterative statements
Java iterative statements
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Java data types
Java data typesJava data types
Java data types
 
Java introduction
Java introductionJava introduction
Java introduction
 
Logistic regression in Machine Learning
Logistic regression in Machine LearningLogistic regression in Machine Learning
Logistic regression in Machine Learning
 
Anomaly detection (Unsupervised Learning) in Machine Learning
Anomaly detection (Unsupervised Learning) in Machine LearningAnomaly detection (Unsupervised Learning) in Machine Learning
Anomaly detection (Unsupervised Learning) in Machine Learning
 
Machine Learning Performance metrics for classification
Machine Learning Performance metrics for classificationMachine Learning Performance metrics for classification
Machine Learning Performance metrics for classification
 
Machine learning Introduction
Machine learning IntroductionMachine learning Introduction
Machine learning Introduction
 

Recently uploaded

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Recently uploaded (20)

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

Problem solving using Programming

  • 1. Problem Solving Dr. Kuppusamy .P Associate Professor / SCOPE Dr. Kuppusamy P
  • 2. Problem Statement 1: Design an algorithm and draw the flow chart to exchange two values. • Let’s consider two glasses denoted A and B with 30 ml mango juice and 50 ml orange juice. Find out the way to exchange the juice in A and B. Dr. Kuppusamy P
  • 3. • Declare variables • Initialize the values Problem Statement 1: Design an algorithm and draw the flow chart to exchange two values. Dr. Kuppusamy P
  • 4. Problem Statement 1: Design an algorithm and draw the flow chart to exchange two values. Move Glass A value 30 to Glass Temp Move Glass B value 50 to Glass A Dr. Kuppusamy P
  • 5. Problem Statement 1: Design an algorithm and draw the flow chart to exchange two values. Move Glass Temp value 30 to Glass B Dr. Kuppusamy P
  • 6. Problem Statement 1: Design an algorithm and draw the flow chart to exchange two values. Algorithm Step 1. Start Step 2. Declare two variables A, B and one more variable temp Step 3. Read the positive numbers to A and B Step 3. temp ← A Step 4. A ← B Step 5. B ← temp Step 6. Display interchanged numbers in A , B Step 7. Stop Dr. Kuppusamy P
  • 7. Problem Statement 1: Design an algorithm and draw the flow chart to exchange two values. Algorithm Step 1. Start Step 2. Declare two variables A, B and one more variable temp Step 3. Read the positive numbers to A and B Step 3. temp ← A Step 4. A ← B Step 5. B ← temp Step 6. Display interchanged numbers in A , B Step 7. Stop Read the positive numbers to A and B temp ← A A ← B B ← temp Display interchanged numbers in A , B Stop Start Declare variables A, B, temp Dr. Kuppusamy P
  • 8. Problem Statement 2: Design an algorithm and draw the flow chart to exchange two values without using temporary variable. Algorithm Step 1. Start Step 2. Declare two variables A, B Step 3. Read the positive numbers as A and B Step 3. A ← A + B Step 4. B ← A - B Step 5. A ← A - B Step 6. Display interchanged numbers in A , B Step 7. Stop E.g. A = 7, B= 5 A = 7 + 5 =12 B = 12-5 =7 A= 12 - 7 =5 Dr. Kuppusamy P
  • 9. Problem Statement 2: Design an algorithm and draw the flow chart to exchange two values without using temporary variable. Algorithm Step 1. Start Step 2. Declare two variables A, B Step 3. Read the positive numbers as A and B Step 3. A ← A + B Step 4. B ← A - B Step 5. A ← A - B Step 6. Display interchanged numbers in A , B Step 7. Stop E.g. A = 7, B= 5 A = 7 + 5 =12 B = 12-5 =7 A= 12 - 7 =5 Read the positive numbers to A and B A ← A + B B ← A - B A ← A - B Display interchanged numbers in A , B Stop Start Declare variables A, B Dr. Kuppusamy P
  • 10. Problem Statement 3: Design an algorithm and draw the flow chart to find the sum of individual digits for the given non negative integer. Step 1. Start Step 2. Declare variable n Step 3. Read non negative integer (n) Step 4. Initialize result ← 0 Step 5. Repeat until n > 0 Step 5.1 result ← result + (n % 10) Step 5.2 n ← n / 10 Step 6. Display result Step 7. Stop E.g. Iteration: 1 n = 76 result = 0 + (76 % 10) n = 76/10 Iteration: 2 n = 7 result = 6 + (7 % 10) n = 7/10 Dr. Kuppusamy P
  • 11. Repeat Yes No Problem Statement 3: Design an algorithm and draw the flow chart to find the sum of individual digits for the given non negative integer. Step 1. Start Step 2. Declare variable n Step 3. Read non negative integer (n) Step 4. Initialize result ← 0 Step 5. Repeat until n > 0 Step 5.1 result ← result + (n % 10) Step 5.2 n ← n / 10 Step 6. Display result Step 7. Stop Read the positive number n result ← result + (n % 10) n ← n / 10 Display the result Stop Start Declare variable n Repeat until n >0 Dr. Kuppusamy P
  • 12. Problem Statement 4: Design an algorithm and draw the flow chart to find the sum of given set of n positive integer. Step 1. Start Step 2. Declare variables n, sum, a, i Step 3. Read total numbers value (n) and ‘n’ positive integers in array ‘a’ Step 4. Initialize sum ← 0 , i ← 0 Step 5. Repeat until i < n Step 5.1 sum ← sum + a[i] Step 5.2 i ← i + 1 Step 6. Display sum Step 7. Stop n = 3 a[] = {2, 3, 4} sum = 0 , i=0 Iteration: 1 sum = 0 + 2 i = i +1 Iteration: 2 sum = 2 + 3 i = i +1 Iteration: 3 sum = 5 + 4 i = i +1 Dr. Kuppusamy P
  • 13. Problem Statement 4: Design an algorithm and draw the flow chart to find the sum of given set of n positive integer. Step 1. Start Step 2. Declare variables n, sum, a Step 3. Read total numbers value (n) and ‘n’ positive integers in array ‘a’ Step 4. Initialize sum ← 0, i ← 0, Step 5. Repeat until i < n Step 5.1 sum ← sum + a[i] Step 5.2 i ← i + 1 Step 6. Display sum Step 7. Stop Repeat Yes No Read total numbers value (n) and ‘n’ integers in array ‘a’ sum ← sum + a[i] i ← i + 1 Display the sum Stop Start Declare variable n, sum, a Repeat until i <n Dr. Kuppusamy P
  • 14. Problem Statement 5: Design an algorithm and draw the flow chart to find the number of digits in given number Sample Input 1: 4582 Sample Output 1: The number of digits in 4582 is 4 Algorithm Step 1. Start Step 2. Declare variables Step 3. Read the input Step 4. Initialize count ← 0 Step 4. Repeat until n !=0 Step 5.1 count ← count + 1 Step 5.2 n ← n / 10 Step 6. Display count Step 7. End Iteration: 1 count = 0 + 1 n= 4582 /10 Iteration: 2 count = 1 + 1 n= 458 /10 Iteration: 3 count = 2 + 1 n= 45 /10 Iteration: 4 count = 3 + 1 n= 4 /10 Iteration: 5 n != 0 → False Dr. Kuppusamy P
  • 15. Problem Statement 6: Design an algorithm and draw the flow chart to find Factorial computation of given number Sample Input 1: 4! Sample Output 1: 24 Step 1. Begin Step 2. Declare variables Step 3. Read the decimal number n Step 4. Initialize fact ← 1, i ← 1 Step 4. if (n != 0) Step 4.1. Repeat until 1 to n Step 4.1.1 fact ← fact * i Step 4.1.2 increment i Step 5. Display fact Step 7. End Iteration: 1 fact = 1 * 1 i = i +1 Iteration: 2 fact = 1 * 2 i = i +1 Iteration: 3 fact = 2 *3 i = i +1 Iteration: 4 fact = 6 * 4 i = i +1 Iteration: 5 i < =n → False Dr. Kuppusamy P
  • 16. Problem Statement 7: Design an algorithm and draw the flow chart to find Sine function computation Step 1. Begin. Step 2. Read the input x and n Step 3. Convert x value to radius using rad ← 3.14/180*x. Step 4. Initialize sum ← rad, sign ← -1. Step 5. Repeat for i ← 3 to n in increment by 2. Step 5.1 power ← pow(rad, i). Step 5.2 factorial ← factorial*(i-1)*i. Step 5.3 result ← power / factorial. Step 5.4 sum ← sum + (sign * result). Step 5.5 k ← k*(-1). Step 6. Display the sum as sine series result. Step 7. End. Dr. Kuppusamy P Repeat Yes No Read the input x and n power ← pow(rad, i). factorial ← factorial*(i-1)*i. result ← power / factorial. sum ← sum + (sign * result). k ← k*(-1) Display the sum Stop Start Declare variable Repeat until i <n Initialize sum, sign
  • 17. Problem Statement 8: Design an algorithm and draw the flow chart to generate Fibonacci sequence Step 1. Begin Step 2. Get Non-negative decimal limit n Step 3. Initialize num1 ← 0, num2 ← 1 Step 4. Display num1 and num2 Step 5. Repeat until 1 to n- 2 Step 5.1 num3 ← num1 + num2 Step 5.2 Display num3 Step 5.3 num1 ← num2 Step 5.4 num2 ← num3 Step 6. End Dr. Kuppusamy P Input : 5 Output: 0, 1, 1, 2, 3, 5
  • 18. Problem Statement 9: Design an algorithm and draw the flow chart to Reverse the digits of an integer Step 1. Begin Step 2. Get Non-negative integer num Step 3. Initialize reversed ← 0 Step 4. Repeat until num > 0 Step 4.1 digit ← n % 10 Step 4.2 reversed ← (reversed * 10) + digit; Step 4.3 num ← num / 10 Step 5. Display reversed Step 6. End Dr. Kuppusamy P Input : 598 Output: 895
  • 19. Problem Statement 10: Design an algorithm and draw the flow chart to Decimal to Binary conversion Step 1. Begin Step 2. Get a Positive decimal number (n) Step 3. Initialize result as null Step 4. if (n > 1) Step 4.1. Repeat until n < 2 Step 4.1.1 Remainder ← n % 2 Step 4.1.2 Append remainder with result Step 4.1.3 n ← n / 2 Step 5. Append n with result Step 6. Display the reverse of result Step 7. End Dr. Kuppusamy P Input : 3 Output: 011 Repeat Yes No Read integer n Remainder ← n % 2 Append remainder with result n ← n / 2 Append n with result Display the reverse of result Stop Start Declare variable Initialize result as null Repeat until n<2
  • 20. References Dr. Kuppusamy P • Herbert Schildt, “Java: The Complete Reference”, McGraw-Hill Education, Tenth edition, 2017. • https://www.sitesbay.com