Question

In: Computer Science

Please write a C++ program to find the largest number among three numbers using nested if...else...

Please write a C++ program to find the largest number among three numbers using nested if...else statements


You need to prompt the user to enter three integer numbers from the keyboard, and then display the largest number among the three.
Please create a function to find the largest number among three numbers, and call the maxAmongThree function in the main function.

Solutions

Expert Solution

#include <iostream>
using namespace std;
// function declaration
int MaxAmongThree(int n1, int n2,int n3);
int main() {
float n1, n2, n3,result; //local variables....

cout << "Enter three numbers: "; //take input from user...
cin >> n1 >> n2 >> n3; //three numbers...
result=MaxAmongThree( n1,n2,n3); //function calling...
cout<<"Largest among three number is "<<result; //print final result....

}
//function definition...
int MaxAmongThree(int n1,int n2,int n3){
//nested if else....
if((n1 >= n2) && (n1 >= n3))
return n1; //return n1..
else if ((n2 >= n1) && (n2 >= n3))
return n2; //return n2...
else
return n3; //return n3...


}


Related Solutions

C++: Write correct C++ code for a nested if-else if-else structure that will output a message...
C++: Write correct C++ code for a nested if-else if-else structure that will output a message based on the logic below. A buyer can pay immediately or be billed. If paid immediately, then display "a 5% discount is applied." If billed, then display "a 2% discount is applied" if it is paid in 30 days. If between 30 and 60 days, display "there is no discount." If over 60 days, then display "a 3% surcharge is added to the bill."...
• Write a C++ program to find the largest umber, smallest number and sum of all...
• Write a C++ program to find the largest umber, smallest number and sum of all the element of a given array of 20 integers • Note − Declare array to 20 numbers − Input values for 20 array elements − Find largest number − Find smallest number − Find sum of all numbers • Display the results
Write in C programming using if and else statements only please!!! Write a program that plays...
Write in C programming using if and else statements only please!!! Write a program that plays the following card game: The user starts out with a pot of $100. At each hand of the game, the dealer and the player are dealt a random number between 1 and 52. The player wins $20 if his/her number is greater than the dealer's number; otherwise they lose $20.
Please write program in c++ with using pointer. create a function that can find the number...
Please write program in c++ with using pointer. create a function that can find the number of even numbers that are between the maximum and minimum elements of an given array.The program have to use pointer. example 8 -1 2 2 1 9 2 4 0 output: 2
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 3 Search list for some items as follows: a. Use the binary search algorithm to search the list. (You may need to modify the algorithm given in this chapter to count the number of comparisons.) b. Use the binary search algorithm to search the list, switching to a sequentialsearch when the size...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 2 Use any sorting algorithm to sort list.
In C++ Write a program to find the number of comparisons using binarySearch and the sequential...
In C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 5.1 Use a random number generator to fill list.
Write a program in C++ to find the number of comparisons using binarySearch and the sequential...
Write a program in C++ to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. a. Use a random number generator to fill list. b. Use any sorting algorithm to sort list. c. Search list for some items as follows: i. Use the binary search algorithm to search the list. (You may need to modify the algorithm given in this chapter to count the number of comparisons.)...
Write a C program that counts the number of odd numbers with using function count() within...
Write a C program that counts the number of odd numbers with using function count() within the set. The set has only one negative number which determines the end of set.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT