- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find maximum among x^(y^2) or y^(x^2) where x and y are given in C++
In this problem, we are given two values x and y. Our task is to find maximum among x^(y^2) or y^(x^2) where x and y are given.
Let’s take an example to understand the problem,
Input: x = 4, y = 3
Output: 3^(4^2)
Explanation:
x^(y^2) = 4^(3^2) = 4^9 = 262144
y^(x^2) = 3^(4^2) = 3^16 = 43046721
Solution approach
One approach can be to calculate both values and then print the maximum of both. But this method does not work when the values are large.
A simple and easy approach is using natural log (ln) which will be the solution easier.
ln(x^(y^2)) = (y^2) * ln(x)
ln(y^(x^2)) = (x^2) * ln(y)
Here, the values are not directly proportional to x and y. So, let’s divide the values by (x^2)*(y^2). This makes the value,
ln(x^(y^2)) / (x^2)*(y^2) = ln(x) / (x^2)
ln(y^(x^2)) / (x^2)*(y^2) = ln(y)/ (y^2)
These values are inversely proportional to the resulting value.
If x > y, then x^(y^2) < y^(x^2)
Program to illustrate the working of our solution,
Example
#include <iostream> using namespace std; bool checkGreaterVal(int x, int y) { if (x > y) return false; else return true; } int main() { int x = 3; int y = 5; cout<<"The greater value is "; if(checkGreaterVal(x, y)) cout<<x<<"^("<<y<<"^2)"; else cout<<y<<"^("<<x<<"^2)"; return 0; }
Output
The greater value is 3^(5^2)
- Related Articles
- Verify : (i) ( x^{3}+y^{3}=(x+y)left(x^{2}-x y+y^{2}right) )(ii) ( x^{3}-y^{3}=(x-y)left(x^{2}+x y+y^{2}right) )
- Factorize:$4(x - y)^2 - 12(x -y) (x + y) + 9(x + y)^2$
- If ( 2 x+y=23 ) and ( 4 x-y=19 ), find the values of ( 5 y-2 x ) and ( frac{y}{x}-2 ).
- Expand ( (x-y)^{2}-2(x-y)
- Factorize:( x^{2}+y-x y-x )
- Simplify:$x^2 (x-y) y^2 (x + 2y)$
- From the choices given below, choose the equation whose graphs are given in Fig. ( 4.6 ) and Fig. 4.7.For Fig. 4. 6(i) ( y=x )(ii) ( x+y=0 )(iii) ( y=2 x )(iv) ( 2+3 y=7 x )For Fig. ( 4.7 )(i) ( y=x+2 )(ii) ( y=x-2 )(iii) ( y=-x+2 )(iv) ( x+2 y=6 )"
- Given $(x^{2}+y^{2})$=74 and xy =35, find the value of:a) x+yb) x-y
- Find $25 x^{2}+16 y^{2}$, if $5 x+4 y=8$ and $x y=1$.
- Factorize:( x^{3}-2 x^{2} y+3 x y^{2}-6 y^{3} )
- If $frac{x+1}{y} = frac{1}{2}, frac{x}{y-2} = frac{1}{2}$, find x and y.
- 1. Factorize the expression ( 3 x y - 2 + 3 y - 2 x )A) ( (x+1),(3 y-2) )B) ( (x+1),(3 y+2) )C) ( (x-1),(3 y-2) )D) ( (x-1),(3 y+2) )2. Factorize the expression ( mathrm{xy}-mathrm{x}-mathrm{y}+1 )A) ( (x-1),(y+1) )B) ( (x+1),(y-1) )C) ( (x-1),(y-1) )D) ( (x+1),(y+1) )
- Simplify: ( frac{11}{2} x^{2} y-frac{9}{4} x y^{2}+frac{1}{4} x y-frac{1}{14} y^{2} x+frac{1}{15} y x^{2}+frac{1}{2} x y ).
- Solve the following pairs of equations:( frac{2 x y}{x+y}=frac{3}{2} )( frac{x y}{2 x-y}=frac{-3}{10}, x+y ≠ 0,2 x-y ≠ 0 )
- Factorize:$2(x+y)^2 - 9(x+y) -5$
