write an algorithm to find largest of two numbers
Answers
Algorithm to find the largest of two numbers is given below:
STEP 1: START.
STEP 2: Accept the first number, say A.
STEP 3: Accept the second number, say B.
STEP 4: Check if A > B. If true, display A.
STEP 5: Check if B > A. If true, display B.
STEP 6: Check if A == B. If true, print - "Both are equal."
STEP 7: STOP.
A sample Python program for the same:
a=int(input('Enter first number: '))
b=int(input('Enter second number: '))
if a>b:
print(a,'is the largest number.')
elif a<b:
print(b,'is the largest number.')
else:
print('Both are equal.')
Algorithm: An algorithm is defined as a step by step procedure to solve any given problem. It may also be defined as a sequence of instructions to perform a specific task. It is always written in simple language and in precise manner.
Characteristics Of A Good Algorithm:
- An algorithm should have 0 or more well defined input.
- An algorithm should have 1 or more well defined output. It algorithm must product a result.
- It must be clear and precise.
- It should be independent of any programming language.
- It must terminate after a finite number of steps.
- An algorithm should be feasible with the available resources and so on.