Advertisement
BrianCobani

Lab3

Feb 18th, 2020
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3.  
  4. double power(double b,int a){//b = base , a = exponent
  5. int product;
  6. int i;
  7. if(b = 0.0 && a >= 0){
  8. product == 0.0;
  9. return product;
  10. }
  11. else if(b = 0.0 && a < 0){
  12. product == INFINITY;
  13. return product;
  14. }
  15. else if(b != 0.0 && a == 0){
  16. product == 1.0;
  17. return product;
  18. }
  19. else if(b != 0.0 && a < 0){
  20. b = 1.0/a;
  21. a = b * -1;
  22. }
  23.  
  24. for(i = 1; i < a; i++){
  25.  
  26. product = b;
  27. return product;
  28. }
  29. }
  30.  
  31. int main(){
  32. int a;
  33. double b;
  34. double product;
  35.  
  36. printf("Enter an exponent: (or -9999 to quit)");
  37. scanf("%d", &a);
  38.  
  39. while(a != -9999){
  40. printf("Enter it's base:\n");
  41. scanf("%lf", &b);
  42. product = power(b , a);
  43. printf("The answer is: %lf \n ", product);
  44.  
  45. printf("Enter a exponent: (or -9999 to quit)");
  46. scanf("%d", &b);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement