Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- double power(double b,int a){//b = base , a = exponent
- int product;
- int i;
- if(b = 0.0 && a >= 0){
- product == 0.0;
- return product;
- }
- else if(b = 0.0 && a < 0){
- product == INFINITY;
- return product;
- }
- else if(b != 0.0 && a == 0){
- product == 1.0;
- return product;
- }
- else if(b != 0.0 && a < 0){
- b = 1.0/a;
- a = b * -1;
- }
- for(i = 1; i < a; i++){
- product = b;
- return product;
- }
- }
- int main(){
- int a;
- double b;
- double product;
- printf("Enter an exponent: (or -9999 to quit)");
- scanf("%d", &a);
- while(a != -9999){
- printf("Enter it's base:\n");
- scanf("%lf", &b);
- product = power(b , a);
- printf("The answer is: %lf \n ", product);
- printf("Enter a exponent: (or -9999 to quit)");
- scanf("%d", &b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement