Menghitung jarak 2 titik dan titik tengahnya :
Disini akan membahas soal mencari nilai jarak dan titik tengah 2 titik dengan komponen Analisis, Algoritma, Flowchart, Bahasa C++ semoga bermanfaat :)
- Analisis :
2. Input : b
3. Input : c
4. Input : d
5. Proses : A <- (a + b)/2
6. Proses : B <- (c + d)/2
7. Proses : T <- sqrt(((c-a)*(c-a))+((d-b)*(d-b)))
8. Output : A
9. Output : B
10. Output : T
- Algoritma:
a : float (input)
b : float (input)
c : float (input)
d : float (input)
A : float (output)
B : float (output)
T : float (output)
2. Deskripsi
read (a,b,c,d)
A <- (a + b)/2
B <- (c + d)/2
T <- sqrt(((c-a)*(c-a))+((d-b)*(d-b)))
write (A,B,T)
- Flowchart :
RUN :
- Bahasa C++ :
int main(int argc, char *argv[])
{
float T;
float A;
float B;
float a;
float b;
float c;
float d;
cout<< "Titik X1= ";
cin >> a;
cout<<"Titik X2= ";
cin >> b;
cout<<"Titik Y1= ";
cin >> c;
cout<<"Titik Y2= ";
cin >> d;
A =(a+b)/2;
B =(c+d)/2;
T = sqrt(((c-a)*(c-a))+((d-b)*(d-b)));
cout << "Maka Jarak dan Titik Tengahnya :" << endl;
cout << "Jarak X= "<<A << endl;
cout << "Jarak Y= "<<B << endl;
cout << "Titik tengah= "<<T << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
RUN :
0 komentar:
Posting Komentar