Skip to main content

Write a function int power (int x, int n) to return x^n without using pow function

#include <stdio.h>

#include <math.h>

void main()

{

  

   int z =(power(3,7));

    printf("%d",z);

}


int power(int x,int n)

{

    int y=x;

    if(n==0)

    return 1;

    else if (n==1)

    return x;

    else if(n>1)

    {

        while(n>1)

        

        {

            x=x*y;

            n--;

        }

    }

    

  return x ;

}


OUTPUT : 2187

Comments

Popular posts from this blog

unix commands