Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- using namespace std;
- int main(int argc, char** argv) {
- cout<<"podaj ilość argumentow"<<endl;
- int n;
- cin>>n;
- int x[n];
- int y[n];
- int i;
- for(i=0;i<n;i++){
- cout<<"podaj argument nr "<<i<<endl;
- cin>>x[i];
- }
- for(i=0;i<n;i++){
- cout<<"podaj wynik funkcji "<<i<<endl;
- cin>>y[i];
- }
- int j;
- for (i=0;i<n;i++){
- for(j=i+1;j<n;j++){
- if(x[i]==x[j]){
- cout<<"podales bledne x"<<endl;
- return -1;
- }
- }
- }
- double arg;
- double l;
- double w;
- cout<<"podaj argument";
- cin>>arg;
- if(arg>=x[0]&&arg<=x[n-1])
- {
- w=0;
- for (i=0;i<n;i++){
- l=1;
- for(j=0;j<n;j++){
- if(i!=j){
- l=l*((arg-x[j])/(x[i]-x[j]));
- }
- }w=w+(y[i]*l);
- }
- cout<<w;
- }else cout<<"argument z poza zakresu";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement