Q:

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

0

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).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now