Pow Function Different output power (10.2) and pow (10, n), where n = 2?

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){
    int n = 2;
    int z = 2*pow(10,n);
    int y = pow(10,n);
    printf("%d %d" , z , y);

    return 0;
}

Output is : 199 99

When I use 2instead of nhow int z = 2*pow(10,2) int y = pow(10,2).

Output is 200 100   

I know how to fix this problem.

It is excluded if, instead of integers, zthey yare float.

I want to know how really C does an integer listing for swimming and other conversions?

Why use 2instead nfixes the problem?

Refresh

This question. What happens here in the pow function? Discusses this topic and has some good answers.

+4
source share

No one has answered this question yet.

Source: https://habr.com/ru/post/1613094/


All Articles