Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Program to find greater value between a^n and b^n in C++
In this tutorial, we will be discussing a program to find greater value between a^n and b^n.
For this we will be provided with three numbers. Our task is to calculate a^n and b^n and return back the greater of those values.
Example
#include <bits/stdc++.h>
using namespace std;
//finding the greater value
void findGreater(int a, int b, int n){
if (!(n & 1)) {
a = abs(a);
b = abs(b);
}
if (a == b)
cout << "a^n is equal to b^n";
else if (a > b)
cout << "a^n is greater than b^n";
else
cout << "b^n is greater than a^n";
}
int main(){
int a = 12, b = 24, n = 5;
findGreater(a, b, n);
return 0;
}
Output
b^n is greater than a^n
Advertisements