Compute Power Manually
C++
xxxxxxxxxx
using namespace std;
int main()
{
int exponent;
float base, result = 1;
cout << "Enter base and exponent respectively: ";
cin >> base >> exponent;
cout << base << "^" << exponent << " = ";
while (exponent != 0) {
result *= base;
--exponent;
}
cout << result;
return 0;
}
Enter base and exponent respectively: 3.4 5 3.4^5 = 454.354
Prefix Increment ++ operator overloading with return type
C++
xxxxxxxxxx
using namespace std;
class Check
{
private:
int i;
public:
Check(): i(0) { }
// Return type is Check
Check operator ++()
{
Check temp;
++i;
temp.i = i;
return temp;
}
void Display()
{ cout << "i = " << i << endl; }
};
int main()
{
Check obj, obj1;
obj.Display();
obj1.Display();
obj1 = ++obj;
obj.Display();
obj1.Display();
return 0;
}
i = 0 i = 0 i = 1 i = 1
Linux - How to Install anc-api-tools
Linux - How to Install curvedns
Python - Check if a Number is Positive, Negative or 0
Linux - How to Install zenmap
C - Count Number of Digits in an Integer
C++ - Check Whether a Number is Prime or Not
JavaScript - Check Whether a String Starts and Ends With Certain Characters
C - Find Largest Number Using Dynamic Memory Allocation
Kotlin - Reverse a Number
Kotlin - Round a Number to n Decimal Places
C++ - Check Leap Year
Linux - How to Install zfs-test
Linux - How to Install xbitmaps
Linux - How to Install zstd
Python - Writing Excel (XLSX) Files
Java - Reverse a Number
GoLang - Base64 Encoding
Java - Create Pyramid and Pattern
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month