CSCI07 Midterm 25%
CSCI07 Midterm 25%
Given three numbers, write a program that outputs the number with the greatest value among the three. Use the conditional ?: (ternary) operator that we have studied so far (HINT: You will need to use two sets of ?: to solve this). For example, given the numbers 10, 23 and 5, your program should output number1 = 10 number2 = 23 number3 = 5 C++ Int main() { int num1=10, num2=23, num3=5 max=0; cout<< number 1 is << num1 << \n number2 is << num2 << \n number3 is << num3\n; max = (number1<number2)?number2:number1; max = (max<number3)?number3:max;
cout<<The highest among the three is << max; return 0; } JAVA { public static void main(String[] args) { int num1=10, num2=23, num3=5 max=0; System.out.println(number1 is +num1+\nnumber2 is +num2+\nnumber3 is +num3); max = (number1<number2)?number2:number1; max = (max<number3)?number3:max; System.out.println(The highest number is +max+.); } { VB.NET Dim number1 As Integer Dim number2 As Integer Dim number3 As Integer Dim max As Integer number1 = 10 number2 = 23 number3 = 5 max = IIf((number1 < number2), number2, number1) max = IIf((max < number3), number3, max) TextBox1.Text = max