This C Program computes the Value of X ^ N. The program uses power function defined in math library.
Here is source code of the C program to computes the Value of X ^ N. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C program to compute the value of X ^ N given X and N as inputs
long int power(int x, int n);
long int x, n, xpown;
printf("Enter the values of X and N \n");
scanf("%ld %ld", &x, &n);
xpown = power(x, n);
printf("X to the power N = %ld\n", xpown);
/* Recursive function to computer the X to power N */
long int power(int x, int n)
if (n == 1)
else if (n % 2 == 0)
/* if n is even */
return (pow(power(x, n/2), 2));
/* if n is odd */
return (x * power(x, n - 1));
$ cc pgm55.c -lm $ a.out Enter the values of X and N 2 5 X to the power N = 32
Sanfoundry Global Education & Learning Series – 1000 C Programs.