Write a program to find a^n, where a and n can be any positive integer.Define a recursive function power ( ) to perform the operation.
#include <stdio.h>
#include <conio.h>
int power ( int a, int n );
int power ( int a, int n )
{
static int p=1;
if ( n == 0 )
return p;
p = power ( a, n - 1 ) * a;
}
void main ( )
{
int a, p = 1, n;
clrscr ( );
printf("\n\n\n\t\t Enter the number..:"); scanf("%d",&a);
printf("\n\t\t Enter the power...:"); scanf("%d",&n);
p = power ( a, n );
printf("\n\n\t\t %d ^ %d = %d",a,n,p);
getch ( );
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
int power ( int a, int n );
int power ( int a, int n )
{
static int p=1;
if ( n == 0 )
return p;
p = power ( a, n - 1 ) * a;
}
void main ( )
{
int a, p = 1, n;
clrscr ( );
printf("\n\n\n\t\t Enter the number..:"); scanf("%d",&a);
printf("\n\t\t Enter the power...:"); scanf("%d",&n);
p = power ( a, n );
printf("\n\n\t\t %d ^ %d = %d",a,n,p);
getch ( );
}
Click here to contact us
No comments:
Post a Comment