All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Finding the maximum (Posted on 2004-04-21)
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.)

 See The Solution Submitted by e.g. Rating: 4.0000 (5 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 Charlie's Program | Comment 11 of 16 |
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)")
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 ")
End While
dblNumberA *= 10 ^ intPowerOf10
'
dblNumberB = 666
While dblNumberB = 666
Console.WriteLine("Please enter another whole number (not 666)")
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 ")
End While
dblNumberB *= 10 ^ intPowerOf10
'
dblNumberC = 666
While dblNumberC = 666
Console.WriteLine("Please enter another whole number (not 666)")
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 ")
End While
dblNumberC *= 10 ^ intPowerOf10
'
Console.WriteLine("Starting time of compare: " & TimeOfDay)
FindMax(dblNumberA, dblNumberB, dblNumberC)
Console.WriteLine("Pres Enter to Continue")
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

 Search: Search body:
Forums (0)