C program to find xᵑ using recursion :
#include< stdio.h >
#include< conio.h >
void main()
{
int n,x,y;
int expo (int x, int n);
clrscr();
printf("Enter the values of x and n:");
scanf("\t%d \t%d",&x,&n);
y=expo(x,n);
printf("The value of x raise to n is %d",y);
getch();
}
int expo (int x, int n)
{
if(n==1)
return x;
else
return (x*expo(x,n-1));
}
OUTPUT :
Enter the values of x and n:2 3
The value of x raise to n is 8
#include< stdio.h >
#include< conio.h >
void main()
{
int n,x,y;
int expo (int x, int n);
clrscr();
printf("Enter the values of x and n:");
scanf("\t%d \t%d",&x,&n);
y=expo(x,n);
printf("The value of x raise to n is %d",y);
getch();
}
int expo (int x, int n)
{
if(n==1)
return x;
else
return (x*expo(x,n-1));
}
OUTPUT :
Enter the values of x and n:2 3
The value of x raise to n is 8
No comments :
Post a Comment