#include <stdio.h>
#include <stdlib.h>
float power (float a, int n);
void main()
{
float a, p;
int n;
printf("Enter a and n\n") ;
scanf("%f%d",&a,&n) ;
p=power(a,n) ;
printf("%f raised. to power %d is %f\n",a,n,p);
}
float power(float a, int n)
{
if(n==0)
return(1);
else
return(a*power(a,n-1));
}
output::
Enter a and n
5
2
5.000000 raised. to power 2 is 25.000000
#include <stdlib.h>
float power (float a, int n);
void main()
{
float a, p;
int n;
printf("Enter a and n\n") ;
scanf("%f%d",&a,&n) ;
p=power(a,n) ;
printf("%f raised. to power %d is %f\n",a,n,p);
}
float power(float a, int n)
{
if(n==0)
return(1);
else
return(a*power(a,n-1));
}
output::
Enter a and n
5
2
5.000000 raised. to power 2 is 25.000000
No comments:
Post a Comment