Using only standard math operators (+, -, *, /) and functions (absolute value, square root, powers, and so on), give a function that calculates MAX(A,B,C).
Alternate version, for programmers only: using any language (BASIC, C, Excel, whatever) find the maximum of A, B, and C, but be careful when writing the program, because you cannot use the ">" key, for it's broken (thus writing things like IF A>B is impossible...) and you cannot use the "M" key either, for it's also broken (...and writing H=MAX(A,B) is also not possible.)
Here is Charlie's program coded in Visual Basic.
Imports System
Imports System.Runtime.InteropServices
Imports System.Math
Module Module1
Sub Main()
Dim dblNumberA As Double
Dim dblNumberB As Double
Dim dblNumberC As Double
Dim intPowerOf10 As Integer
dblNumberA = 666
While dblNumberA = 666
Console.WriteLine("Please enter a whole number (not 666)")
dblNumberA = Int(Console.ReadLine())
End While
intPowerOf10 = 666
While intPowerOf10 = 666
Console.WriteLine("Please enter a whole number P (not 666) " & _
"to complete the formula: ")
Console.WriteLine("First number = " & Str(dblNumberA) & _
" * 10 ^ P ")
intPowerOf10 = Int(Console.ReadLine())
End While
dblNumberA *= 10 ^ intPowerOf10
'
dblNumberB = 666
While dblNumberB = 666
Console.WriteLine("Please enter another whole number (not 666)")
dblNumberB = Int(Console.ReadLine())
End While
intPowerOf10 = 666
While intPowerOf10 = 666
Console.WriteLine("Enter a whole number P (not 666) " & _
"to complete the formula:")
Console.WriteLine("Second number = " & Str(dblNumberB) & _
" * 10 ^ P ")
intPowerOf10 = Int(Console.ReadLine())
End While
dblNumberB *= 10 ^ intPowerOf10
'
dblNumberC = 666
While dblNumberC = 666
Console.WriteLine("Please enter another whole number (not 666)")
dblNumberC = Int(Console.ReadLine())
End While
intPowerOf10 = 666
While intPowerOf10 = 666
Console.WriteLine("Enter a whole number P (not 666) " & _
"to complete the formula:")
Console.WriteLine("Third number = " & Str(dblNumberC) & _
" * 10 ^ P ")
intPowerOf10 = Int(Console.ReadLine())
End While
dblNumberC *= 10 ^ intPowerOf10
'
Console.WriteLine("Starting time of compare: " & TimeOfDay)
FindMax(dblNumberA, dblNumberB, dblNumberC)
Console.WriteLine("Pres Enter to Continue")
Console.ReadLine()
End Sub
Sub FindMax(ByRef dblNumberA, ByRef dblNumberB, ByRef dblNumberC)
Dim dblNumberAB As Double
Dim dblNumberABC As Double
Dim dblAbsWorkarea As Double
Console.WriteLine("For numbers " & Str(dblNumberA) & _
" " & Str(dblNumberB) & " " & Str(dblNumberC))
dblNumberAB = (dblNumberA + dblNumberB) _
/ 2 + Abs(dblNumberA - dblNumberB) / 2
dblNumberABC = (dblNumberAB + dblNumberC) / 2 + _
Abs(dblNumberAB - dblNumberC) / 2
Console.WriteLine("Max is " & Str(dblNumberABC))
Console.WriteLine("Ending time of compare: " & TimeOfDay)
End Sub
End Module
Edited on April 23, 2004, 5:29 am
|
Posted by Penny
on 2004-04-22 17:17:06 |