C Program to Write a program to calculate pow(x,n) - IProgramX

Q. Write a program to accept two integers x and n and compute x^n


Program

#include <stdio.h>
#include <math.h>
void main()
{
 long int x,n,pow=1,j=1;
 printf("Enter the values of X and n : ");
 scanf("%d %d",&x,&n);
 pow=x;
while(n!=j)
{
pow=pow*x;
j++;
}
 printf(" %d to the power %d = %d",x,n,pow);
}

Output:

Enter the values of X and n : 4 5
 4 to the power 5 = 1024

Post a Comment

0 Comments