Write a program to find the exponential power of a number. In this C Programming example, we are going to write a program to find the exponential power of any number.
What is Exponential Power?
Multiplying a number with itself for multiple times is exponents likewise 5² = 25, 5³=125, 12³=1728
here 5,12 are the base and the 2 and 3 is the power of that bases
Algorithm of Exponential Power
- Include library and create the main method with void as its return type
- Take input of the number and power to which it has to raise
- Performing the operation and then printing the result with an appropriate message
C Program to find the exponential power of a number
#include<stdio.h> void main(){ int a,b,i,r; printf("enter the number"); scanf("%d",&a); printf("enter the power"); scanf("%d",&b); for(i=1;b>=i;i++){ r=r*a; } printf("the result is %d",r); }
Explanation of the Source Code
- On-Line no:1 including the library to take and give input and output respectively
- On-Line no:2 initializing the main method with void as its return type
- On-Line no:3 declaring variables
- On-Line no:4 message for the user to give the base number
- On-Line no:5 using scanf to take and place at address
- On-Line no:6 message for the user to give the base number
- On-Line no:7 using scanf to take and place at address
- On-Line no:8 for loop to iterate the program again and again until we get the desired output
- On-Line no:9 updating the value each time for the further increment
- On-Line no:10 closing the scope of for loop so that the print message will be shown once only
- On-Line no:11 printing the message of output appropriately
- Closing other scopes
Output
In this blog, we have learned how to create a program to calculate the exponential power of a number