**New course!**Every coder should learn

**Generative AI!**

0

# Even after typecasting at line 18, why does it keep printing 0 as output for any given input ?

#include <stdio.h> #include <math.h> int main() { int x,x1,y,y1; float z; printf("Enter the first cartesian point "); scanf("%d %d",&x,&y); printf("%d %d\n",x,y); printf("Enter the second cartesian point "); scanf("%d %d",&x1,&y1); printf("%d %d\n",x1,y1); int a = pow(x1-x,2); int b = pow(y1-y,2); z = (float)sqrt(a+b); printf("distance between the two points= %d",z); return 0; }

1 Answer

+ 13

see sqrt definition:
double sqrt (double x );
https://en.m.wikibooks.org/wiki/C_Programming/math.h/sqrt
so typecast like so:
int x = 5;
double y = sqrt( (double) x )