Advertisement
18126

Day3(ex6)

Jul 8th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int pwr(int a, int b, int c) {
  6.     if(b == 0) {
  7.         return 0;
  8.     }
  9.     if(c == 1) {
  10.         return a;
  11.     }
  12.     return pwr(a*a, b, c-1);
  13. }
  14.  
  15. int main() {
  16.     int a, b, counter;
  17.     printf("Enter a: ");
  18.     scanf("%d", &a);
  19.     printf("Enter b: ");
  20.     scanf("%d", &b);
  21.     counter = b;
  22.     printf("Result: %d", pwr(a, b, counter));
  23.     return EXIT_SUCCESS;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement