# C Program to Calculate Power of a Number

In this article, we are going to **write a c program to calculate power of a number**

We will make this program in the following way -:

- C Program to Calculate Power of a Number
**Using For Loop** - C Program to Calculate Power of a Number
**Using While Loop** - C Program to Calculate Power of a Number
**Using Do While Loop** - C Program to Calculate Power of a Number
**Using Function** - C Program to Calculate Power of a Number
**Using Recursion**

To make this program, we will use the following concept given below.

If you do not know about these topics well, then you may not understand this program, so you should know about them in detail from the link given above.

Now without wasting time let’s start programming.

**Contents**hide

## C Program to Calculate Power of a Number Using For Loop

### Algorithm

- Program Start
- Declare Variable
- Input base number and Power Number
- Calculate Power
- Display Result
- Program End

### Program

```
//C Program to Calculate Power of a Number Using For Loop
#include <stdio.h>
void main()
{
int base, n, i;
int result = 1;
printf("Enter the base number : ");
scanf("%d", &base);
printf("Enter power number : ");
scanf("%d", &n);
for(i=1; i<=n; i++)
{
result = result*base;
}
printf("Given number is %d and power is %d and result is : %d",base, n, result);
}
```

### Output

```
Enter the base number : 5
Enter power number : 3
Given number is 5 and power is 3 and result is : 125
```

## C Program to Calculate Power of a Number Using While Loop

### Program

```
//C Program to Calculate Power of a Number Using While Loop
#include <stdio.h>
void main()
{
int base, n, i = 1;
int result = 1;
printf("Enter the base number : ");
scanf("%d", &base);
printf("Enter power number : ");
scanf("%d", &n);
while(i<=n)
{
result = result*base;
i++;
}
printf("Given number is %d and power is %d and result is : %d",base, n, result);
}
```

### Output

```
Enter the base number : 7
Enter power number : 3
Given number is 7 and power is 3 and result is : 343
```

## C Program to Calculate Power of a Number Using Do While Loop

### Program

```
//C Program to Calculate Power of a Number Using Do While Loop
#include <stdio.h>
void main()
{
int base, n, i = 1;
int result = 1;
printf("Enter the base number : ");
scanf("%d", &base);
printf("Enter power number : ");
scanf("%d", &n);
do
{
result = result*base;
i++;
}while(i<=n);
printf("Given number is %d and power is %d and result is : %d",base, n, result);
}
```

### Output

```
Enter the base number : 10
Enter power number : 3
Given number is 10 and power is 3 and result is : 1000
```

## C Program to Calculate Power of a Number Using Function

### Algorithm

- Program Start
- Declare Variable
- Input base number and Power Number
- Calling Function
- Calculate Power
- Display Resullt
- Program End

### Program

```
//C Program to Calculate Power of a Number Using For Loop
#include <stdio.h>
void power(int base, int n)
{ int i, result =1;
for(i=1; i<=n; i++)
{
result = result*base;
}
printf("Given number is %d and power is %d and result is : %d",base, n, result);
}
void main()
{
int base, n;
printf("Enter the base number : ");
scanf("%d", &base);
printf("Enter power number : ");
scanf("%d", &n);
power(base,n);
}
```

### Output

```
Enter the base number : 10
Enter power number : 3
Given number is 10 and power is 3 and result is : 1000
```

## C Program to Calculate Power of a Number Using Recursion

### Program

```
//Prime Number Program In C Using Recursion
#include<stdio.h>
int recursion(int ,int );
void main()
{
int base, n;
int result;
printf("Enter the base number : ");
scanf("%d", &base);
printf("Enter power number : ");
scanf("%d", &n);
result= recursion(base, n);
printf("Given number is %d and power is %d and result is : %d",base, n, result);
}
int recursion(int base,int n)
{ if(a!=0)
{
base = base * recursion(base ,n-1);
return(base);
}
else
return 1;
}
```

### Output

```
Enter the base number : 3
Enter power number : 2
Given number is 3 and power is 2 and result is : 9
```

**Read More -:**

- Download C Language Notes Pdf
- C Language Tutorial For Beginners
- C Programming Examples With Output
- 250+ C Programs for Practice PDF Free Download

## Conclusion

So friends, in this article, we have written **a c program to calculate power of a number** in this ways -:

- C Program to Calculate Power of a Number Using For Loop
- C Program to Calculate Power of a Number Using While Loop
- C Program to Calculate Power of a Number Using Do While Loop
- C Program to Calculate Power of a Number Using Function
- C Program to Calculate Power of a Number Using Recursion

If you have difficulty to understand any program or have any doubts or questions, then tell me in the comment below.