google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a program to find x^y using recursion - 2nd puc computer science

Write a program to find x^y using recursion

// Write a program to find x^y using recursion

#include<iostream.h>

#include<conio.h>

float expo(float a,int n)

{

if(a==0)

return 0.0;

else if(n==0)

return 1.0;

else if(n>0)

return(a*expo(a,n-1));

else

return(1/a*expo(a,n+1));

}

void main()

{

float expo(float,int);

float x;

int y;

clrscr();

cout<<"Enter the base: ";

cin>>x;

cout<<"Enter the exponent: ";

cin>>y;

cout<<x<<"^"<<y<<"="<<expo(x,y);

getch();

}

Write a program to find x^y using recursion Write a program to find x^y using recursion Reviewed by Vision Academy on February 27, 2022 Rating: 5

No comments:

CheckOut

Powered by Blogger.