×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

C program to calculate X^N (X to the power of N) using pow function

pow() is used to calculate the power of any base, this library function is defined in math.h header file. In this program we will read X as the base and N as the power and will calculate the result (X^N - X to the power of N).

pow() function example/program to calculate X^N in c program

/*
C program to calculate X^N (X to the power of N) using 
pow function.
*/
 
#include <stdio.h>
#include <math.h>
 
int main()
{
    int x,n;
    int result;
 
    printf("Enter the value of base: ");
    scanf("%d",&x);
 
    printf("Enter the value of power: ");
    scanf("%d",&n);
     
    result =pow((double)x,n);
 
    printf("%d to the power of %d is= %d", x,n, result);
    getch();
    return 0;
}

Output

Enter the value of base: 3
Enter the value of power: 7
3 to the power of 7 is= 2187

C Basic Programs »

Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement



Copyright © 2024 www.includehelp.com. All rights reserved.