PatrickSwayze

zadanie 2 rozdział 9

Nov 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. float f(float x)
  6. {
  7.     return 2*x-5;
  8. }
  9. void wypelnij(int*n,float *t)
  10. {
  11.     int x,dx;
  12.     cout<<"Okresl ilosc elementow: ";
  13.     cin>>*n;
  14.     dx=(6+2)/(*n-1);
  15.     for (int i=0;i<(*n);i++)
  16.     {
  17.         x=-2+i*dx;
  18.         t[i]=f(x);
  19.     }
  20. }
  21. void wypisz(int*n,float*t)
  22. {
  23.     //cout<<*n;
  24.     for (int i=0;i<*n;i++)
  25.     {
  26.         cout<<"Dla x= "<<i-2<<" funkcja 2x-5= "<<t[i]<<endl;
  27.     }
  28. }
  29. int main()
  30. {
  31.     int n;
  32.     float t[20];
  33.     wypelnij(&n,t);
  34.     wypisz(&n,t);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment