ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมเพื่อค้นหาคุณค่าที่มากขึ้นระหว่าง 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