[go: up one dir, main page]

0% found this document useful (0 votes)
570 views20 pages

Chapter5: Algorithm, Flowchart, Pseudocode: Find Sum of Two Numbers

The document provides pseudocode for several algorithms. It includes algorithms to: 1) Find the sum of two numbers, area and perimeter of a rectangle, area and circumference of a circle, and simple interest. 2) Check if a year is a leap year, if a number is positive or negative, and if a number is even or odd. 3) Categorize a person as child, teenager, or adult based on age. 4) Print natural numbers up to n, print n odd numbers, print the square of a number, and accept 5 numbers and find their average.

Uploaded by

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

Chapter5: Algorithm, Flowchart, Pseudocode: Find Sum of Two Numbers

The document provides pseudocode for several algorithms. It includes algorithms to: 1) Find the sum of two numbers, area and perimeter of a rectangle, area and circumference of a circle, and simple interest. 2) Check if a year is a leap year, if a number is positive or negative, and if a number is even or odd. 3) Categorize a person as child, teenager, or adult based on age. 4) Print natural numbers up to n, print n odd numbers, print the square of a number, and accept 5 numbers and find their average.

Uploaded by

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

Chapter5: Algorithm, Flowchart, pseudocode

Find sum of two numbers


Algorithm Flowchart Pseudocode

Step 1: Start Input numbers, N1, N2


Step 2: Input two numbers say N1 Calculate sum by adding N1 and N2
and N2
Step 3: Find Sum as (Sum = N1 + N2) Display sum
Step 4: Output / Print sum
Step 5 : Stop
P Find Area and Perimeter of a rectangle
Algorithm Flowchart Pseudocode
Step 1: Start INPUT length and breadth as L and
Step 2 :Input side-length and Breadth, B
say L and B Calculate Area by multiplying L and
Step 3 : Find AREA as AREA = L x B B
Step 4 : Find PERIMETER as Calculate Perimeter by double the
PERIMETER = 2 x (L + B) sum of L and B
Step 5 : Print AREA, PERIMETER Display Area and Perimeter
Step 6 : Stop

Find the area and circumference of a circle


Algorithm Flowchart Pseudocode
Step 1 : Start Input Radius
Step 2 : Input radius of the circle, Calculate the Area by multiplying
say Radius 3.14 with the square of radius
Step 3 : Find the Area = 3.14 x Calculate the Circumference by
Radius doubling 3.14 x radius
Find the Circumference = Display Circumference and Area
2 x 3.14 x Radius
Step 4 : Print Area and
Circumference
Step 5 : Stop

.Calculate the simple interest


Algorithm Flowchart Pseudocode
Step 1 : Start Input P, R ,T
Step 2 : Input P, R, T Calculate Simple Interest by multiplying P,
Step 3 : Find simple interest = P x R x T R and T
Step 4 : Print Simple interest Display Simple Interest.
Step 5 : Stop

To check whether a year is a leap year or not


Algorithm Flowchart Pseudocode
Step 1 : Start Input Year
Step 2 : Input Year Check whether Year/4 = 0
Step 3 : Check if Year/4 = 0 If it is divisible, then
If it is divisible by 4, go to step Display “it is a leap year”
4 Else
If it is not divisible by 4, go to Display “It is not a leap year”
step 5
Step 4 : Print “It is a leap
year”
Step 5 : Print “It is not a leap
year”
Step 6 : Stop

To check if a number is positive or negative number


Algorithm Flowchart Pseudocode
Step 1 : Start Input Number
Step 2 : Input Number Check whether Number > 0
Step 3 : Check if Number > 0 If Number is greater than 0 then
If yes, go to step 4 Display “Number is positive”
If no, go to step 5 Else
Step 4 : Print “Number is positive” Display “Number is negative”
Step 5 : Print “Number is negative”
Step 6 : Stop

To check if a number is an odd or an even number


Algorithm Flowchart Pseudocode
Step 1 : Start Input Number
Step 2 : Input Number Check if Number divide by 2 is equal to 0
Step 3 : Check if number/2 = 0 If it is divisible then
If yes, go to step 4 Display “The number is even”
If no, go to step 5 Else
Step 4 : Print “The Number is even” Display “The number is odd”
Step 5 : Print “The Number is odd”
Step 6 : Stop

To categorize a person as either child (<13), teenager (>=13 but <20) or adult (>20), based on age specified
Algorithm Flowchart Pseudocode
Step 1 : Start Input age
Step 2 : Input age Check if age is less than 13 years
Step 3 : Check if age is <13 If yes,
If yes, print “Child” Display “Child”
If no, go to step 4 Else,
Step 4 : Check if age is >= 13 Check if age is more than or equal
and <20 to 13 but less than 20
If yes, print “Teenager” If yes,
If no, go to step 5 Display “Teenager”
Step 5 : Check if age is >20 Else,
If yes, print “Adult” Display “Adult”
If no, go to step 6
Step 6 : Stop

To print all natural numbers up to n


Algorithm Flowchart Pseudocode
Step 1 : Start Input n
Step 2 : Input n as a natural number Initialize I as 1, Natural number as 1
Step 3 : Initialize natural number as 1, i as Check whether I is more than n
1 (Natural number = 1, i = 1) Yes: Stop and come out of checking
Step 4 : Check whether i > n No: print i
If yes, go to step 5 Increment i by 1 (i = i +1)
If no, print i Check again whether I is more than n and
Increment i by 1 ( i = i+i) repeat till condition is satisfied
Step 5 : Stop Stop and come out of checking

. To print n odd numbers


Algorithm Flowchart Pseudocode

Step 1 : Start Input n


Step 2 : Input n Initialize I as 1
Step 3 : i = 1 Check whether 0 comes in a remainder
Step 4 : Check if n%2 != 0 when n is divided by 2
If yes, i = i +2 Yes:
i <=n No: print i
If no, go to step 5 Increment i by 1 (i = i +1)
Step 5 : Stop Check again whether I is more than n and
repeat till condition is satisfied
Stop and come out of checking

To print a square of a number


Algorithm Flowchart Pseudocode

Step 1 : Start N = input "number "


Step 2 : Input n Square = n * n
Step 3 : square = n * n Display square
Step 4 : print square
Step 5 : Stop
To accept 5 numbers and find their average.
Algorithm Flowchart Pseudocode

1. Start A = input first number


2. Input a , b, c , d, e B = input second number
3. Sum a + b + c + d + e C = input third number
4. Average Sum / 5 D = input fourth number
5. Print Average E = input fifth number
6. Stop Sum = a + b + c + d + e
Average = Sum / 5
Display Average

To accept numbers till the user enters 0 and then find their average
Algorithm Flowchart Pseudocode

Step 1: Start INPUT N


Step 2: Input N Initialize count=0, sum=0
Step 3: Initialize count and IS N=0?
sum as 0. (count=0, No: Add N to Sum
sum=0) Add 1 to count
Step 4: Check if N=0 Yes: Find average
If no: sum= sum+N Average is Sum divided by
count=count+1 Count
Repeat until the condition is Print Average
true.
If yes: go to step 5.
Step 5: Average=
sum/count
Step 6: Print Average
Step 7: Stop

To print squares of first n numbers


Algorithm Flowchart Pseudocode

1. Start N = input "a number"


2. Input a number For I in range 0 to n + 1
3. For I in range ( number +1 ) Square = I ** 2
Square = I ** 2 Display square
Print Square
4. Stop

To print cube of a number


Algorithm Flowchart Pseudocode

1. Start N = input a number


2. Input a number Cube = n ** 3
3. Cube = number ** 3 Display cube
4. Print cube
5. Stop

To print the cubes of first n numbers


Algorithm Flowchart Pseudocode

Step 1: Start Initialize i=1


Step 2: Initialize i=1 INPUT n
Step 3: Input n Check if i<=n
Step 4: If i<=n If yes, calculate the Cube by
If yes: Cube=i*i*i multiplying i to itself twice.
Print Cube Display Cube
Increment of i (i=i+1) Increment of i by 1
Repeat until the condition is false. Repeat until condition is false
If no: Go to step 5 If no, Stop
Step 5: Stop

To find the factorial of a given number.


Algorithm Flowchart Pseudocode

Step 1 :Start INPUT N


Step 2 :Input N Initialize I as 1, Factorial as 1
Step 3 :Initialize Factorial as 1, I as 1 Check whether I is less than or
(Factorial = 1, I = 1) equal to N
Step 4 : Check whether I <=N Yes: Calculate Factorial by
Yes: Calculate Factorial as multiplying Factorial by I
Factorial x I Increment by 1 (I = 1+ I)
Increment by 1 (I = I + Check again whether I is less than
1)\ or equal to 1 and repeat till
Repeat this step till condition is satisfied
condition is true No: Stop and come out of
No: Do step 5 checking
Step 5 : Print Factorial Print Factorial
Step 6 : Stop

Find the largest of two numbers


Algorithm Flowchart Pseudocode

Step 1: Start Insert numbers as N1 and N2


Step 2: Input two numbers, say Check whether N1 is greater
N1 and N2 than N2
Step 3: Check if N1 > N2 If N1 is greater than N2 then
If yes: Go to step 4 Display “N1 is greater than
If no : Go to step 5 N2”
Step 4: Print “N1 is greater than Else
N2” Display “N2 is greater than
Step 5: Print “N2 is greater than N1”
N1”
Step 6: Stop

You might also like