Wednesday, 13 July 2016

WRITE A RECURSIVE C FUNCTION TO CALCULATE x^y(x raised to y)(DO NOT USE STANDARD LIBRARY FUNCTION)

#include<stdio.h>
int power(int,int);
main()
{
int x,y,a;
printf("Enter the no");
scanf("%d",&x);
printf("Enter the power");
scanf("%d",&y);
a=power(x,y);
printf("%d",a);
}
int power(int x,int y)
{
int a=1;
if(y==0)
return 1;
else
{
a=x*power(x,y-1);
return a;
}
}


ASSIGNMENT 8)

  TO DEMONSTRATE RECURSION

No comments:

Post a Comment