artur anikin
artur anikin

Reputation: 107

Why does pow works here

From what i know the function pow works only with double and returns double but in this programm everything works fine and its all in int. i just want to understand like so why even though it only works with double here it works with ints

void squre_OF_3_digit_number()
{
    int num;//123
    do
    {
        printf("please enter a 3 digit number--> ");
        scanf_s("%d",&num);
    } while (num>999 || num<100);
    int n0 = pow((num%10),2);
    int n1 = pow(((num%100)/10),2);
    int n2 = pow((num/100),2);
    printf(" %d+%d+%d=%d ",n0,n1,n2,n0+n1+n2);
    
}`

Upvotes: 0

Views: 61

Answers (1)

user20333834
user20333834

Reputation:

I suggest you to go through this page: https://www.geeksforgeeks.org/c-typecasting/

Here, the compiler has automatically converted (called implicit conversion) the int type data to double type data.

Upvotes: 1

Related Questions