0
while (i) {
    printf("Digit (%d) = %d", d, ((num2/(pow(10,(i-1))))%10));
    d++;
    i--;
}

i and d are int values declared earlier on in the function. The error I'm getting is "Operands of '%' have incompatible types 'double' and 'int'."

I keep getting this error message even after fiddling with the values.

2 Answers 2

7

That is because pow returns a double. You will have to typecast it. Change the statement to:

printf("Digit (%d) = %d", d, ((int)(num2/(pow(10,(i-1))))%10));
Sign up to request clarification or add additional context in comments.

Comments

3

In alternative to casting the numerator into int, you could also call fmod() to perform modular computation in terms of floating point numbers.

printf("Digit (%d) = %lf", d, fmod((num2/(pow(10.0,(i-1)))),10.0));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.