_TruELecter_

Untitled

Oct 23rd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. double fRand(double fMin, double fMax)
  6. {
  7. double f = (double)rand() / RAND_MAX;
  8. return fMin + f * (fMax - fMin);
  9. }
  10.  
  11. double CreateFunction (double x, int n){
  12. srand(time(NULL));
  13. double xx = 1, sum = 0, an = 0;
  14. for (int i = 0; i < n + 1; i++) {
  15. an = fRand(0, 5);
  16. std::cout << an << " * x ^ " << i;
  17. if (i < n) {
  18. std::cout << " + ";
  19. }
  20. sum += xx * an;
  21. xx *= x;
  22. }
  23. return sum;
  24. }
  25.  
  26. int main()
  27. {
  28. double res = CreateFunction(1, 10);
  29. std::cout << " = " << res;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment