BistoB
BistoB

Reputation: 11

Pow function in C returns 0

Want to create a program that asks the user to input 2 numbers and output the first number to the power of the second one. Here is my code

void func4()
{

    double f;
    double g;
    double result;
    printf("Enter first number:\n");
    scanf_s("%d", &f);
    printf("Enter second number number:\n");
    scanf_s("%d", &g);
    result = pow(f, g);
    printf("%f", result);
}

But when I put the numbers the output is always zero.

P.S. Libraries stdio.h and math.h are added in the header

Upvotes: 0

Views: 792

Answers (1)

MikeCAT
MikeCAT

Reputation: 75062

%d format specifier is for reading int. You have to use proper specifier. You can use %lf for reading double.

Upvotes: 1

Related Questions