- Related Questions & Answers
- Find multiple of x closest to or a ^ b (a raised to power b) in C++
- Python a += b is not always a = a + b
- Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B in C++
- Count total divisors of A or B in a given range in C++
- Number of Digits in a^b in C++
- Find a palindromic string B such that given String A is a subsequence of B in C++
- Count number of triplets (a, b, c) such that a^2 + b^2 = c^2 and 1<=a<=b<=c<= n in C++
- Program to find N-th term of series a, b, b, c, c, c…in C++
- Construct a Finite Automata for the regular expression ((a+b)(a+b))*.
- Count pairs (a, b) whose sum of squares is N (a^2 + b^2 = N) in C++
- Count pairs (a, b) whose sum of cubes is N (a^3 + b^3 = N) in C++
- Find all pairs (a, b) in an array such that a % b = k in C++
- Minimum Flips to Make a OR b Equal to c in C++
- Find 2^(2^A) % B in C++
- Check if a + b = c is valid after removing all zeroes from a, b and c in C++

- 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 tutorial, we are going to write a program that finds out the larger among the a^{b} and b^{a}

It's a straightforward problem. Let's see the steps to solve it.

- Initialise the values of a and b.
- Take the log of both the values.
- Compute the values of $b\:\log\:a$ and $a\:\log\:b$
- Compare the both values.
- If $a\:\log\:b$ is greater than $b\:\log\:a$, then print b
^{a}is greater. - If $b\:\log\:a$ is greater than $a\:\log\:b$, then print a
^{b}is greater. - Else print both are equal.

Let's see the code.

#include <bits/stdc++.h> using namespace std; int main() { int a = 4, b = 7; long double x = (long double) a * (long double)(log((long double)(b))); long double y = (long double) b * (long double)(log((long double)(a))); if (y > x) { cout << "a ^ b is greater" << endl; }else if (y < x) { cout << "b ^ a is greater" << endl; }else { cout << "Both are equal" << endl; } return 0; }

If you run the above code, then you will get the following result.

a ^ b is greater

If you have any queries in the tutorial, mention them in the comment section.

Advertisements