Google

Program to compute power of a given number x raised to y

Written on:October 2, 2012
Comments are closed

Recursion

Program to compute power of a given number x raised to y

#include <stdio.h>
#include <conio.h>

int power(int x,int n)
{
if(n==0)
return 1;
else
return(x * power(x,n-1));
}

void main()
{
int x,n,res;
clrscr();
printf(“nEnter base?”);
scanf(“%d”,&x);
printf(“nEnter exponent?”);
scanf(“%d”,&n);
res=power(x,n);
printf(“Power of %d raised to %d is %d”,x,n,res);
getch();
}

 

Sorry, the comment form is closed at this time.