- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given two numbers x and y. Our task is to *find larger of x^y and y^x. *

**Problem Description: **The problem is simple, we need to find weather x to the power y is greater than y to the power x.

**Let’s take an example to understand the problem, **

**Input: **x = 4, y = 5

**Output: **1024

**Explanation: **

x^y = 4^5 = 1024

y^x = 5^4 = 625

The solution to the problem is simple. We need to find the value of x^y and y^x and return the maximum of both.

There can be a more mathematically easy way to solve the problem, which is by taking log. So,

*x^y = y*log(x)*.

These values are easy to calculate.

#include <bits/stdc++.h> using namespace std; int main() { double x = 3, y = 7; double ylogx = y * log(x); double xlogy = x * log(y); if(ylogx > xlogy) cout<<x<<"^"<<y; else if (ylogx < xlogy) cout<<y<<"^"<<x; else cout<<"None"; cout<<" has greater value"; return 0; }

3^7 has greater value

- Related Questions & Answers
- Find maximum among x^(y^2) or y^(x^2) where x and y are given in C++
- Find number of pairs (x, y) in an array such that x^y > y^x in C++
- Count Distinct Non-Negative Integer Pairs (x, y) that Satisfy the Inequality x*x + y*y < n in C++
- Find a distinct pair (x, y) in given range such that x divides y in C++
- Count of pairs (x, y) in an array such that x < y in C++
- Maximize the sum of X+Y elements by picking X and Y elements from 1st and 2nd array in C++
- Count Distinct Non-Negative Integer Pairs (x, y) that Satisfy the Inequality x*x +\ny*y < n in C++
- Find the value of the function Y = (X^6 + X^2 + 9894845) % 981 in C++
- Check if a number can be expressed as x^y (x raised to power y) in C++
- What is ternary operator (? X : Y) in C++?
- Write an iterative O(Log y) function for pow(x, y) in C++
- Find the smallest number X such that X! contains at least Y trailing zeros in C++
- Find smallest values of x and y such that ax – by = 0 in C++
- Different X and Y scales in zoomed inset in Matplotlib
- MySQL where column = 'x, y, z'?

Advertisements