There is no way to use the ^ (Bitwise XOR) operator to calculate the power of a number. Therefore, in order to calculate the power of a number we have two options, either we use a while loop or the pow() function.
1. Using a while loop.
#include <stdio.h> int main() { int base, expo; long long result = 1; printf("Enter a base no.: "); scanf("%d", &base); printf("Enter an exponent: "); scanf("%d", &expo); while (expo != 0) { result *= base; --expo; } printf("Answer = %lld", result); return 0; }
2. Using the pow() function
#include <math.h> #include <stdio.h> int main() { double base, exp, result; printf("Enter a base number: "); scanf("%lf", &base); printf("Enter an exponent: "); scanf("%lf", &exp); // calculate the power of our input numbers result = pow(base, exp); printf("%.1lf^%.1lf = %.2lf", base, exp, result); return 0; }
<stdio.h>and<math.h>are usually used instead of"stdio.h"and"math.h". But it looks like GCC doesn't really care.^since the question (and answers) make little sense otherwise. Since peoro answered correctly for your question, you should accept it and move on. If you have another question, then please ask another question. Don't edit this one to make all the work done meaningless.