0

Why my C code is not working ?

#include<stdio.h> #include<math.h> void main() { int X1,X2,Y1,Y2,a,b,c,d; printf("Follow Yogesh Jangid\n"); while(1){ printf("Enter Frist point x coordinate\n"); scanf("%d\n",&X1); printf("Enter Frist point y coordinate\n"); scanf("%d\n",&X2); printf("Your Frist point is (%d,%d)\n",X1,X2); printf("Enter Second point x coordinate\n"); scanf("%d\n",&Y1); printf("Enter Frist point y coordinate\n"); scanf("%d\n",&Y2); printf("Your second point is (%d,%d)\n",Y1,Y2); a=pow((X2-X1),2); b=pow((Y2-Y1),2); d=a+b; c=pow(d,0.5); printf("The distance between points is %d\n\n\n",c); } } This is my code to find distance between points But it is not working properly and not giving right answer. Tell me why it's not working properly.

18th Jan 2020, 3:05 PM
Yogesh Jangid
Yogesh Jangid - avatar
2 Answers
+ 1
I am not sure but I think it should be like this: a=pow((X2-Y2),2); b=pow((X1-Y1),2);
18th Jan 2020, 3:24 PM
Paul
Paul - avatar
0
It's working fine but try to limit loop iterations instead of while(1).. What you may missing is, if you want accurate answers then use float or double values instead of int, and while printing also..
18th Jan 2020, 3:41 PM
Jayakrishna 🇼🇳