i research this program because i dont know how or what is the program of recursion using the exponent and square.please..give the answer because its very difficult to me coz this is my first time..in programming...for those who have mercy to me..please..help me.
What is the program of exponent,square,in recursion in c programming?
/*The following is the code for calculating exponent of a number recursively. Square of a number is a special case of this program.*/
#include%26lt;stdio.h%26gt;
int ex(int a, int x);
int main()
{
int a,x,res;
printf("Enter the value of a\n");
scanf("%d",%26amp;a);
printf("Enter the value of x\n");
scanf("%d",%26amp;x);
res=ex(a,x);
printf("%d^%d=%d\n",a,x,res);
return 0;
}
int ex(int a,int x)
{
if (x==0) return 1;
else return(a*ex(a,x-1));
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment