fork download
  1. #include <stdio.h>
  2.  
  3. //TODO: define a function to evaluate a to the power of b without using predefined functions.
  4. int power(int a, int b)
  5. {
  6. int result = 1;
  7.  
  8. for(int i = 0; i < b; i++)
  9. {
  10. result = result * a;
  11. }
  12.  
  13. return result;
  14. }
  15.  
  16. int main(void) {
  17. //TODO: scan two integer from user, a and b
  18.  
  19. int m, n;
  20. printf("Please enter integer1: ");
  21. scanf("%d", &m);
  22.  
  23. printf("Please enter integer2: ");
  24. scanf("%d", &n);
  25.  
  26. //TODO: call the function you defined above and assign a variable to the result
  27. printf("m to the power of n is equal to: %d\n", power(m, n));
  28.  
  29. //TODO: printout the result
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5280KB
stdin
2
2
stdout
Please enter integer1: Please enter integer2: m to the power of n is equal to: 4