Question

using a C++ code find the largest number from two numbers. also considering the case that...

using a C++ code find the largest number from two numbers. also considering the case that the two numbers are equal.

Homework Answers

Answer #1

Code:

#include <iostream>

//function to find the largest of any given two numbers

int largest(int o,int t){

if (o==t) return o;

else if(o>t) return o;

else return t;

}

//main function testing the above

int main() {

std::cout << "largest(5,3)="<<largest(5,3)<<std::endl;

std::cout << "largest(1,3)="<<largest(1,3)<<std::endl;

std::cout << "largest(2,2)="<<largest(2,2)<<std::endl;

}

output:

largest(5,3)=5
largest(1,3)=3
largest(2,2)=2

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program that finds the largest number among two numbers and store the result in...
Write a program that finds the largest number among two numbers and store the result in any register. Value1: 0x18345678 (hexidecimal) Value2: 0x15678245 (hexidecimal) (Code in ARM assembly language, Using Keil software)
PLease code a C++ program that prompts a user to enter 10 numbers. this program should...
PLease code a C++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the 10 numbers and the average of the 10 numbers please use file i/o and input measures for Handling Errors in C++ When Opening a File
In C++ program that inputs three integers and displays the smallest and largest numbers. It should...
In C++ program that inputs three integers and displays the smallest and largest numbers. It should pass the numbers to two functions. A value returning function determines the smallest number and returns it, and a void function determines the largest number and displays it. Sample run: Enter three numbers: 9 10 7 The smallest number is:7 The largest number is: 10
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers...
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers (choosing between a range of 20 to 90) and then outputs the largest number.
In C language Assignment A palindromic number reads the same both ways. The largest palindrome made...
In C language Assignment A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. Note: this is Project Euler's problem number 4. Functional Requirements MUST correctly calculate the largest palindrome made from the product of two 3-digit numbers. MUST print the value of each factor, as well as their product, separated by commas....
Please code using C# Complete the two methods, highest() and lowest(). Both methods are static with...
Please code using C# Complete the two methods, highest() and lowest(). Both methods are static with a double return type and one integer parameter. Both methods will accept user input of as many numbers as the integer parameter’s value. The highest() method will return the largest number input. The lowest() method will return the smallest number input. Examples: The call highest(3) with user inputs of [5, 60, 2] will return the value of 60 The call lowest(3) with user inputs...
python Write a program to find the largest value. Ask the user to enter three numbers....
python Write a program to find the largest value. Ask the user to enter three numbers. Compare them and report the largest one. [Hint: The user is free to enter any three numbers. Some or all of them may be the same. Take this into consideration when you compare the numbers.] The following are some examples. Enter first number: 7 Enter second number: 14 Enter third number: 10.5 The largest number is: 14.0 Enter first number: 17 Enter second number:...
Write an LC-3 program (machine code) that compares the two numbers located in x3600 and x3601...
Write an LC-3 program (machine code) that compares the two numbers located in x3600 and x3601 and puts the value 0 in R1 if the two numbers are equal, 1 if the first number is larger than the second number, and -1 if the first number is smaller than the second number.
For C++ : find the largest repeating number in a vector. Check : {3 , 4,...
For C++ : find the largest repeating number in a vector. Check : {3 , 4, 16, 2, 3, 16, 98, 4, 2,}
1.Draw a flowchart to read 3 numbers: M, K and N and print the largest number...
1.Draw a flowchart to read 3 numbers: M, K and N and print the largest number of them. 2. Devolve an algorithm that allows the user to enter the count of number in a list followed by these numbers. The algorithm should find and output the minimum and maximum numbers in the list. 3. Develop an algorithm that inputs a series of number and output their average.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT