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.
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...
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.
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.
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,}
Take 10 numbers from the user. Calculate their mean and median with your code, not using...
Take 10 numbers from the user. Calculate their mean and median with your code, not using builtin Matlab functions. Print these values on the screen with a special format using the command: fprintf.
Write an assembly code for a M68CH12 microcontroller that counts from 0000-9999 using even numbers on...
Write an assembly code for a M68CH12 microcontroller that counts from 0000-9999 using even numbers on the seven segment display.