Home » C programs » C basic 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






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.