Anda di halaman 1dari 3

# Program C++ - Interpolasi Kuadratik

#include <iostream>
#include <conio.h>

## using namespace std;

int main()
{
float x1, x2, x3, y1, y2, y3, x, pers1, pers2, pers3, hasil;
cout <<
"=================================================================="
<< endl;
cout << "

## Program C++ - Interpolasi Kuadratik " << endl;

cout <<
"=================================================================="
<< endl;
cout << "

## cout << " " << endl;

cout << "Mencari nilai dari sesuatu yang berada dalam sebuah interval atau " << endl;
cout << " diantara 3 buah titik yaitu (x1,y1), (x2,y2), dan (x3,y3) dengan " << endl;
cout << "

## cout << " " << endl;

cout << "Masukkan nilai x1 : ";
cin >> x1;
cout << "Masukkan nilai y1 : ";
cin >> y1;
cout << "Masukkan nilai x2 : ";
cin >> x2;
cout << "Masukkan nilai y2 : ";
cin >> y2;
cout << "Masukkan nilai x3 : ";
cin >> x3;
cout << "Masukkan nilai y3 : ";
cin >> y3;
cout << " " << endl;

## cout << "Masukkan nilai x yang akan dicari : ";

cin >> x;
cout << " " << endl;

pers1 = ((x-x2)*(x-x3))/((x1-x2)*(x1-x3));
pers2 = ((x-x1)*(x-x3))/((x2-x1)*(x2-x3));
pers3 = ((x-x1)*(x-x2))/((x3-x1)*(x3-x2));
hasil = (y1*pers1)+(y2*pers2)+(y3*pers3);

## cout << "Maka nilai y untuk titik x = ";

cout << x ;
cout << " yang berada di antara ";
cout << "titik ";
cout << " " << endl;
cout << "(";
cout << x1;
cout << ",";
cout << y1;
cout << ")";
cout << ", ";
cout << "(";
cout << x2;
cout << ",";
cout << y2;
cout << ")";
cout << ", dan ";
cout << "(";
cout << x3;
cout << ",";
cout << y3;
cout << ")";
cout << hasil << endl;

getch();
return 0;

### Dapatkan aplikasi gratis kami

Hak cipta © 2021 Scribd Inc.