"Algorithms": Problem 1: Find The Sum, Product and Average of Five Given Numbers
"Algorithms": Problem 1: Find The Sum, Product and Average of Five Given Numbers
Problem 1: Find the sum, product and average of five given numbers.
Planning the solution:
Input: Five given numbers.
Required output: Sum, product and average of five numbers.
Processing: Addition, multiplication and division of numbers.
Algorithm:
Step 1: Start
Let the five numbers be A=2, B=1, C=3, D=5, E=4
Step 2: FIND the sum (SUM)
SUM=A+B+C+D+E
Step 3: FIND the prod (PROD)
PROD=A*B*C*D*E
Step 4: FIND the average (AVG)
AVG=SUM/5
Step 5: Output SUM, PROD, AVG
Step 6: Stop
Problem 2: Find the largest of three unequal numbers.
Planning the solution:
Input: Three unequal numbers.
Required output: largest of three numbers.
Processing: Comparison of each number with the other two one by one.
Algorithm:
Step 1: Start
Let the three numbers be A=10, B=20 and C=30
Step 2: Check if A is the largest number
If A>B and A>C THEN LARGEST= A otherwise GOTO step 4.
Step 3: GOTO step 7.
Step 4: Check if B is the largest number.
If B>A and B>C THEN LARGEST=B otherwise GOTO step 6.
Step 5: GOTO step 7.
Step 6: LARGEST=C
Step 7: output LARGEST
Step 8: Stop
Problem 3: Find acceleration of a moving object for given mass and force
applied.
Planning the solution:
Input: mass and force.
Required output: Acceleration of moving object.
Processing: Divide the force by the mass.
Algorithm:
Step 1: Start
Let the mass (M) be 50 and force (F) be 12.
Step 2: CALCULATE the acceleration (A)
A=F/M
Step 3: Output A
Step 4: Stop
Problem 4: Find the volume of a cube.
Planning the solution:
Input: Length of side of cube.
Required output: Volume of cube.
Processing: side of cube raised to the power of three
Algorithm:
Step 1: Start
Let the length of one side of cube, L be 12
Step 2: CALCULATE the volume, V
V=L3
Step 3: Output V
Step 4: Stop
Problem 5: Find the area of a triangle when the lengths of height and base are
given.
Planning the solution:
Input: Height and base of triangle
Required output: Area of triangle
Processing: Multiply height with base and divide by two
Algorithm:
Step 1: Start
Let the height, H be 10 and the base, B be 15.
Step 2: CALCULATE the area, A
A= (B*H)/2
Step 3: Output A
Step 4: Stop
Problem 6: Find the exponent of a given number.
Planning the solution:
Input: A number and its exponent.
Required output: Exponent of given number.
Processing: Multiply the number as many times as its exponent.
Algorithm:
Step 1: Start
Let the number, N be 8 and its exponent, E be 5
Step 2: Initialize product (P) and K to 1
P=1, K=1
Step 3: FIND the product (P)
P=P*N
Step 4: Increment K by 1
K=K+1
Step 5: Check if the value of K is less than or equal to E
IF K<=E GOTO Step 3 otherwise GOTO Step 6
Step 6: Output P
Step 7: Stop
Problem 7: Print odd numbers from 1 to 100.
1 3 5 7 9 11 … 99
Planning the solution:
Input: This problem has no input.
Required output: Printing odd numbers from 1 to 100.
Processing: Initialize a variable to 1 and keep printing it with an increment of 2 till
99.
Algorithm:
Step 1: Start
Initialize variable K to 1
K=1
Step 2: Output K
Step 3: Increment K by 2
K=K+2
Step 4: Check if the value of K is less than 100