SHARE
TWEET

for rohit

a guest Jul 23rd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // wap to calculate b^n using recursion.
  2.  
  3. #include <stdio.h>
  4. int power(int n1, int n2);
  5. int main()
  6. {
  7.     int base, powerRaised, result;
  8.     printf("Enter base number: ");
  9.     scanf("%d",&base);
  10.     printf("Enter power number(positive integer): ");
  11.     scanf("%d",&powerRaised);
  12.     result = power(base, powerRaised);
  13.     printf("%d^%d = %d", base, powerRaised, result);
  14.     return 0;
  15. }
  16. int power(int base, int powerRaised)
  17. {
  18.     if (powerRaised != 0)
  19.         return (base*power(base, powerRaised-1));
  20.     else
  21.         return 1;
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top