Advertisement
Guest User

Untitled

a guest
May 25th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. double n;
  5. double pc=-15;
  6. double kc = 15;
  7. double potega(double liczba, int wykladnik){
  8. double wynik=liczba;
  9. int i;
  10. for(i=1;i<wykladnik;i++){
  11. wynik=wynik*liczba;
  12. }
  13. return wynik;
  14. }
  15.  
  16. double calkazzakresu(double p, double k){
  17. double suma =0;
  18. while(p<=k){
  19. double tmp2 = (8*potega(p,5)-2*potega(p,4)+15*potega(p,2)-24*p+18);//wartosc jednego boku trapezu
  20. double tmp =(8*potega(p+n,5)-2*potega(p+n,4)+15*potega(p+n,2)-24*(p+n)+18); //wartosc drugiego boku trapezu
  21. suma=suma+n*((tmp+tmp2)/2);
  22. p=p+n;
  23. }
  24. return suma;
  25.  
  26. }
  27.  
  28. int main(int argc, char **argv){
  29. int potok[2];
  30. double sumac=0;
  31. int iloscPrzedzialow;
  32. double dlugoscprzedzialu;
  33. iloscPrzedzialow = atoi(argv[1]);
  34. n = atof(argv[2]);
  35. dlugoscprzedzialu = (kc-pc)/iloscPrzedzialow;
  36. double tmpPc=pc;
  37. int i;
  38. pipe(potok);
  39. for(i=0; i<iloscPrzedzialow; i++){
  40. double tmp4 = tmpPc;
  41. write(potok[1],&tmp4,sizeof(tmp4));
  42. tmpPc=tmpPc+dlugoscprzedzialu;
  43. }
  44.  
  45.  
  46.  
  47. for(i=0;i<iloscPrzedzialow;i++){
  48. if (fork() ==0){
  49. double tmp2;//wartosc zapisana do potoku
  50. double tmp3;//wartosc odczytana z potoku
  51. read(potok[0], &tmp3, sizeof(tmp3));
  52. tmp2 = calkazzakresu(tmp3,tmp3+dlugoscprzedzialu);
  53. write(potok[1],&tmp2,sizeof(tmp2));
  54. printf("potomek %d: ",i);
  55. printf("%f\n",tmp2);
  56. exit(0);
  57. }
  58. }
  59.  
  60. while (wait(0) > 0){};
  61. for (i=0; i<iloscPrzedzialow;i++){
  62. double tmp3; //wartosc odczytana z potoku
  63. read(potok[0], &tmp3, sizeof(tmp3));
  64. sumac=sumac+tmp3;
  65.  
  66. }
  67.  
  68. printf("suma: %f\n",sumac);
  69. printf("n: %f\n",n);
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement