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; }

19th May 2018, 11:11 AM
Md Arshad Ali
Md Arshad Ali - avatar
1 ответ
+ 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 )
19th May 2018, 12:07 PM
jay
jay - avatar