Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<unistd.h>
- #include<string.h>
- using namespace std;
- void help(){
- cout << "Chebeshev function\nn - number of iteration\nx - argument of function\nPlease, enter thevalue of n and x.\n Use Enter for it\n";
- }
- double chebeshev(int n, double x)
- {
- if (n == 0)
- {
- return 1;
- }
- else if (n == 1)
- {
- return x;
- }
- else
- {
- double polinom;
- polinom = 2 * x * chebeshev(n - 1, x) - chebeshev(n - 2, x);
- return polinom;
- }
- }
- int main(int argc, char ** argv){
- if ((argc == 2) && (!strcmp("help", argv[1])))
- {
- help();
- exit(0);
- }
- int pid;
- int c[2];
- int s[2];
- pipe(c);
- pipe(s);
- if((pid = fork()) == -1)
- {
- perror("fork");
- exit(1);
- }
- if((pid = fork()) == 0)
- {
- int n;
- cin >> n;
- write(c[1], &n, sizeof(n));
- double x;
- cin >> x;
- write(c[1], &x, sizeof(x));
- close(c[1]);
- double result1;
- read(s[0], &result1, sizeof(result1));
- close(s[1]);
- cout << "Result = " << result1 << endl;
- }
- else
- {
- int n1;
- read(c[0], &n1, sizeof(n1));
- double x1;
- read(c[0], &x1, sizeof(x1));
- close(c[0]);
- double result = chebeshev(n1, x1);
- write(s[1], &result, sizeof(result));
- close(s[1]);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment