Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- double fRand(double fMin, double fMax)
- {
- double f = (double)rand() / RAND_MAX;
- return fMin + f * (fMax - fMin);
- }
- double CreateFunction (double x, int n){
- srand(time(NULL));
- double xx = 1, sum = 0, an = 0;
- for (int i = 0; i < n + 1; i++) {
- an = fRand(0, 5);
- std::cout << an << " * x ^ " << i;
- if (i < n) {
- std::cout << " + ";
- }
- sum += xx * an;
- xx *= x;
- }
- return sum;
- }
- int main()
- {
- double res = CreateFunction(1, 10);
- std::cout << " = " << res;
- }
Advertisement
Add Comment
Please, Sign In to add comment