程序用 C++ 查找 a^n 和 b^n 之间的较大值
在本教程中,我们讨论一个程序,用于查找 a^n 和 b^n 之间的较大值。
对于此问题,我们提供了三个数字。我们的任务是计算 a^n 和 b^n,并返回这些值中较大的一个。
示例
#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;
}输出
b^n is greater than a^n
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP