Home C Programming Language / Programs / Create a power function using c
🚀 Programming Example

Create a power function using c

👁 976 Views
💻 Practical Program
📘 Step Learning
Create a power function using c

💻 Program Code

#include<stdio.h>
void power(float, float);
void main()
{
float x, n;
printf("Enter The value of x and n : ");
scanf("%f%f",&x,&n);
power(x,n);
}

void power(float x, float n)
{
int i;
float result = 1;

 for(i= 0; i<n; i++)
 {
 result = (result*x);
 }  
 
 printf("%.1f^%.1f = %f",x,n,result);
 
}
                        

🖥 Program Output

Enter The value of x and n : 2  2
2.0^2.0 = 4.000000Press any key to continue . . .
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.