2001 01 17
Home ] Up ]

 

//prog002.cpp
//Author: Kailash Chandra
//01/17/2001
/*
Write a function that will give you two highest
values of the three integer values.
Examples:
Input:  1, 2, 3
Output: 2, 3
Input:  2, 2, 3
Output: 2, 3
Input:  1, 1, 1
Output: 1, 1
Input:  a, b, c
Output: x, y so that x and y are the highest values
nPlan1: Find max of three, find max of remaining
oPlan2: Sort and pick the last two
oPlan3: if a is max then max of b and c .....
oPlan4: Find minimum and drop it
Plan2: Sort and pick the last two
Algorithm:
do the following 2 times:
  if a > b then swap a, b
  if b > c then swap b, c
  end do
x = c
y = b


oPlan3: if a is max then max of b and c .....
Algorithm:
if a>=b and a>=c then
    x = a
    if b>c then y = b else y = c
  else if b>=c and b>=a then
    x = b
    if a>c then y = a else y = c
  else 
    x = c
    if a>b then y = a else y = b
  end if
oPlan4: Find minimum and drop it
Algorithm:
if a<=b and a<=c then
    x = b, y = c
  else if b<=c and b<=a then
    x = a, y = c
  else 
    x = a, y = b
  end if