C program to calculate power of a number
- The program takes two integer from user and then calculate power.
- In case 2 is base number and 3 is exponent number. (2*2*2)
#includeOutputint main() { int base, exp; // integer values long long result = 1; // constant values printf("Enter a base number: "); // User enter scanf("%d", &base); //storing values printf("Enter an exponent: "); // User enter scanf("%d", &exp); // storing values while (exp != 0) // while loop { result = result * base; --exp; } printf("Answer = %lld", result); // finalize result return 0; }
Ente a base number 3 Enter exponent number 4 Answer = 81Happy Coding
Thanks for visiting my Blog.
Have any problem, feel free to contact us via Email : uoslondy@gmail.com
Have a good day!
0 comments:
Post a Comment