algorithm_practice
algorithm_practice
Solution:
Step1: Start
Step 2: Declare variables N1, N2, TEMP
Step 3: Read N1, N2, TEMP
Step 4: TEMP=N1
N1=N2
N2=TEMP
Step 5: Print N1, N2
Step 6: Stop
Flowchart: Swapping contents of two variables
Ex2. Write an Algorithm and flowchart to find largest of three numbers.
Solution:
Step1: Start
Step 2: Declare three variables A, B, C;
Step 3: Read three variables A, B, C;
Step 4: Check if A is greater than B
If true, then check if A is greater than C.
If true, print 'A' as the greatest number.
If false, print 'C' as the greatest number.
If false, then check if B is greater than C.
If true, print 'B' as the greatest number.
If false, print 'C' as the greatest number.
Step 5: End
Solution:
ࢇ࢞ + ࢈࢞ + ࢉ =
Solution:
Step 4: x1(-b+d)/2 x a
Step 5: x2(-b-d)/2 x a
Step 6: Print x1, x2
Step 7: Stop
A classic example of Divide and Conquer is Merge Sort demonstrated below. In Merge Sort, we
divide array into two halves, sort the two halves recursively, and then merge the sorted halves.
halves