0% found this document useful (0 votes)
19 views16 pages

Illustrative Problems

Python programs

Uploaded by

PPTV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views16 pages

Illustrative Problems

Python programs

Uploaded by

PPTV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

ILLUSTRATIVE PROBLEMS

Factorial Number
Formula :
n! = 1*2*3*........*n
4! = 1*2*3*........*4 = 24
• Factorial(number):
• SET Fact = 1 and i=1
• While i< number
• Fact=Fact*i
• i=i+1
• Print Fact
• ENDWHILE
• END
Guess an integer in a range
Algorithm:
Step1: Start
Step 2: Declare n, guess
Step 3: Read n
Step 4: Read guess
Step 5: If guess>n, then
Print your guess is too high
Else
Step6:If guess<n, then
Print your guess is too low
Else
Step 7:If guess==n,then
Print Good job
Else
Nope
Step 6: Stop
pseudo code:
Begin
Read Guess
IF guess>n
PRINT Guess is High
ELSE
IF guess<n
PRINT Guess is Low
ELSE
IF guess==n
PRINT Good Job
ELSE
Nope
END
Find minimum in a list
Step 1: Start
Step 2: Read n
Step 3:Initialize i=0
Step 4: If i<n, then goto step 4.1, 4.2 else goto step 5
Step4.1: Read a[i]
Step 4.2: i=i+1 goto step 4
Step 5: Compute min=a[0]
Step 6: Initialize i=1
Step 7: If i<n, then go to step 8 else goto step 10
Step 8: If a[i]<min, then goto step 8.1,8.2 else goto 8.2
Step 8.1: min=a[i]
Step 8.2: i=i+1 goto 7
Step 9: Print min
Step 10: Stop
Step 10: Stop
Find minimum in a list
Insert a card in a list of sorted cards

Step 1: Start
Step 2: Read n
Step 3:Initialize i=0
Step 4: If i<n, then goto step 4.1, 4.2 else goto step 5
Step4.1: Read a[i]
Step 4.2: i=i+1 goto step 4
Step 5: Read item
Step 6: Calculate i=n-1
Step 7: If i>=0 and item<a[i], then go to step 7.1, 7.2 else goto step 8
Step 7.1: a[i+1]=a[i]
Step 7.2: i=i-1 goto step 7
Step 8: Compute a[i+1]=item
Step 9: Compute n=n+1
Step 10: If i<n, then goto step 10.1, 10.2 lse goto st 11
Step10.1: Print a[i]
Step10.2: i=i+1 goto step 10
Step 11: Stop
BEGIN
READ n
FOR i=0 to n, then
READ a[i]
INCREMENT i
END FOR
READ item
FOR i=n-1 to 0 and item<a[i], then
CALCULATE a[i+1]=a[i]
DECREMENT i
END FOR
COMPUTE a[i+1]=a[i]
COMPUTE n=n+1
FOR i=0 to n, then
PRINT a[i]
INCREMENT i
END FOR
Tower of Hanoi

Tower of Hanoi is a mathematical puzzle where we have


three rods and n disks.
The objective of the puzzle is to move the entire stack to
another rod, obeying the following simple rules:

• Only one disk can be moved at a time.


• Each move consists of taking the upper disk from one of
the stacks and placing it on top of another stack i.e. a disk
can only be moved if it is the uppermost disk on a stack.
• No disk may be placed on top of a smaller disk.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy