0% found this document useful (0 votes)
33 views

CSCI07 Midterm 25%

The document provides code samples in C++, Java, and VB.NET to write a program that takes three input numbers and outputs the number with the greatest value using ternary operators. The C++ code takes in three numbers, uses two ternary operators to compare the numbers and assign the greatest to a max variable, and outputs the max. Similarly, the Java and VB.NET code also take in three numbers, use ternary operators to find the max, and output the maximum number.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

CSCI07 Midterm 25%

The document provides code samples in C++, Java, and VB.NET to write a program that takes three input numbers and outputs the number with the greatest value using ternary operators. The C++ code takes in three numbers, uses two ternary operators to compare the numbers and assign the greatest to a max variable, and outputs the max. Similarly, the Java and VB.NET code also take in three numbers, use ternary operators to find the max, and output the maximum number.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

DELEN, Michelle A.

CSCI07 Midterm (Part)

July 28, 2012

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

You might also like