Write a C program to find power of any number using for loop. The program should not use built-in pow() function. How to find power of any number without using built in library functions in C programming.

Input base: 2

Input exponent: 5

Output 2^5: 32

We have already seen how to use the library function pow() to find power of any number efficiently. Here we will see how we can find power of any number without using inbuilt library function pow(). We will use loop to find power of any number. Also check this program using another programming method - C program to find power of any two number using recursion.

Happy coding ;)

**Example:**Input base: 2

Input exponent: 5

Output 2^5: 32

### Required knowledge

Basic C programming, For loop, Base and exponentsWe have already seen how to use the library function pow() to find power of any number efficiently. Here we will see how we can find power of any number without using inbuilt library function pow(). We will use loop to find power of any number. Also check this program using another programming method - C program to find power of any two number using recursion.

### Program to find power of any number

/** * C program to find power of any number using for loop */ #include <stdio.h> int main() { int base, exponent; long long power = 1; int i; /* Reads base and exponent from user */ printf("Enter base: "); scanf("%d", &base); printf("Enter exponent: "); scanf("%d", &exponent); /* Multiples base, exponent times*/ for(i=1; i<=exponent; i++) { power = power * base; } printf("\n%d ^ %d = %lld", base, exponent, power); return 0; }

**Note:**Some compilers do not support long long data type hence if your compiler reports any errors in the program just change the data type from long long with long type also replace the format specifier %lld to %ld.

Output

Enter base: 2

Enter exponent: 5

2 ^ 5 = 32

Enter exponent: 5

2 ^ 5 = 32

Happy coding ;)

### You may also like

- Loop programming exercises index.
- C program to calculate square root of any number.
- C program to convert length from centimeter to meter and kilometer.
- C program to convert temperature from Fahrenheit to Celsius.
- C program to enter P, T, R and find Compound Interest.
- C program to find sum of digits of any number.
- C program to find sum of all natural numbers between 1 to n.
- C program to find sum of first and last digit of any number.
- C program to find factors of any number.
- C program to find factorial of any number.
- C program to generate Fibonacci series up to n terms.
- C program to find cube of any number using function.

I like your theme of choice for web journal however need to recommend you for sharing some more data with respect to your subject so we can comprehend your idea all the more unmistakably. Buzz Apps

ReplyDeleteThanks noman, and yes I am working over it. To ensure the readers can get all from this single site.

Delete