Problem Description
Write a Program to calculate power using recursion.CODING ARENA::
#include <stdio.h>
int power(int n1,int n2);
int main()
{
int a,b,c;
scanf("%d%d",&a,&b);
c=power(a,b);
printf("%d^%d = %d",a,b,c);
return 0;
}
int power(int a,int b)
{
if(b!=0)
return(a*power(a,b-1));
else
return 1;
}
Test Case 1
Input (stdin)2 3
Expected Output2^3 = 8
Test Case 2
Input (stdin)2 2
Expected Output2^2 = 4
No comments:
Post a Comment