Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- #include <sys/wait.h>
- double silnia(double x)
- {
- if(x==0)
- return 1;
- else if(x==1)
- return 1;
- else
- return x*silnia(x-1);
- }
- int main(){
- //char *myfifo = "Katarzyna1_2";
- //char *mkfifo = "Katarzyna2_3";
- //int mkfifo(myfifo, 0666);
- int fd[2];
- char arr[100], wynik[100];
- pipe(fd);
- if(fork() > 0){
- double X;
- double Eps;
- close(fd[0]);
- printf("X = ");
- scanf("%lf", &X);
- sprintf(arr, "%lf", X);
- write(fd[1], arr, 101);
- printf("Eps = ");
- scanf("%lf", &Eps);
- sprintf(arr, "%lf", Eps);
- write(fd[1], arr, 101);
- close(fd[1]);
- sleep(1);
- }
- else {
- close(fd[1]);
- double X, Eps;
- read(fd[0], wynik, 101);
- X=strtod(wynik, NULL);
- read(fd[0], wynik, 101);
- Eps = strtod(wynik,NULL);
- close(fd[0]);
- int fd1[2];
- pipe(fd1);
- if(fork() > 0){
- double i=0;
- double fragment;
- do{
- fragment=pow(X,i)/silnia(i);
- i++;
- sprintf(arr, "%lf", fragment);
- write(fd1[1], arr, 101);
- printf("%lf\n ", fragment);
- }
- while(fragment >= Eps);
- return 0;
- }
- else{
- double sum=0, tmp;
- close(fd1[1]);
- while(read(fd1[0], wynik, 101)>0){
- tmp=strtod(wynik, NULL);
- sum += tmp;
- }
- printf("Suma: %f\n", sum);
- printf("Wynik = %f\n", exp(X));
- return 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement