दो बिंदुओं के निर्देशांक दिए गए हैं, कार्य उनके बीच की दूरी निकालना है।
द्वि-आयामी तल में दो बिंदु A(x1, y1) और B(x2, y2) हैं। दूरी का सूत्र:
√[(x2 - x1)² + (y2 - y1)²]
दृष्टिकोण
- निर्देशांक x1, y1, x2, y2 इनपुट लें।
- सूत्र लागू करें।
- दूरी प्रिंट करें।
एल्गोरिदम
START फंक्शन two_dis(x1, y1, x2, y2) dis = sqrt(pow(x2-x1,2) + pow(y2-y1,2) * 1.0) dis प्रिंट करें मुख्य फंक्शन x1=4, y1=9, x2=5, y2=10 सेट करें two_dis(x1, y1, x2, y2) कॉल करें STOP
C कोड उदाहरण
#include <stdio.h>
#include <math.h>
void two_dis(float x1, float y1, float x2, float y2) {
float dis = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0);
printf("Distance between 2 points are : %f", dis);
}
int main() {
float x1 = 4, y1 = 9, x2 = 5, y2 = 10;
two_dis(x1, y1, x2, y2);
return 0;
}
आउटपुट
Distance between 2 points are : 1.414214