Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. using namespace std;
  5.  
  6. double x2(double x)
  7. {
  8.     return x * x;
  9. }
  10.  
  11. void zapiszFun(double (*f)(double x), double a, double b, int n, string nazwaPliku)
  12. {
  13.     double odleglosc = (b - a) / n;
  14.  
  15.     fstream plik;
  16.     plik.open(nazwaPliku, ios::out);
  17.     if (plik.is_open())
  18.     {
  19.         for (int i = 0; a+i <= b; i += odleglosc)
  20.         {
  21.             plik << a + i << "\t" << f(a + i) << endl;
  22.         }
  23.     }
  24.     plik.close();
  25.  
  26. }
  27. //n-liczba czesci na ktora dzielimy przedzial [a,b]
  28.  
  29.  
  30. int main()
  31. {
  32.     zapiszFun(x2, -1, 3, 4, "plik.txt");
  33.  
  34.     system("pause");
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement