Calculating x^n

Problem Statement
Write a c program to calculate xn using iterative function
#include<stdio.h>
int main()
{
  int x,n,x_pow_n,temp;
  printf("enter the value of x ");
  scanf("%d",&x);
  printf("enter the value of n ");
  scanf("%d",&n);
  x_pow_n=1;
  temp=n; 
  while(temp>0)
    {
      x_pow_n=x_pow_n*x;
      temp=temp-1;
    }
  printf("%d^%d=%d \n",x,n,x_pow_n);
  return 0;
}

No comments:

Post a Comment