Simple problem .

distance between two point (x1,x2)and (y1,y2)is governed by the formula
D2=(x2-x1)2+(y2-y1)2
write a program to compute D .
but my problem is;;;

Here , how can i take as integer X1, X2 , Y1, Y2 e.t.c ?
I'm not sure what your question is. Are you asking about converting integers to doubles? As in, the square root in the formula would change their type?
Simple solution: ask the user to enter the integers.:)
no bro,
my question was , how can i take integer like x1,x2,x3,....
Variables:
x2, x2, y1, y2, d

Probably want double, or cast them, as they're likely going to have decimal places after the square root
use iostream and cin.
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
int main() {
	int x1,x2,y1,y2;
	cout << "Please enter x1:"; cin >> x1;
	cout << "Please enter x2:"; cin >> x2;
	cout << "Please enter y1:"; cin >> y1;
	cout << "Please enter y2:"; cin >> y2;
	//function that calculates D goes here
	return 1;
}
[b]is it correct? [/b]

#include<stdio.h>

int main()

{
int x1,x2,y1,y2;
double s;
printf("Please enter your values x1,x2,y1,y2\n");
scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
s=(pow((x2-x1),2)-pow((y2-y1),2));
printf("%lf",s);




getch();
return 0;

}
It is incorrect at least because you showed early another expression

D2=(x2-x1)2+(y2-y1)2

Though even your original expression is invalid because it does not determine the distance.:)
Topic archived. No new replies allowed.