Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Bartosz Bojda gr. GKiO2
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- float calka(float x1, float x2, float n)
- {
- float suma = 0;
- while (x1 < x2)
- {
- float wynik1 = 8 * x1 * x1 * x1 * x1 * x1 - 2 * x1 * x1 * x1 * x1 + 15 * x1 * x1 - 24 * x1 + 18;
- x1 += n;
- float wynik2 = 8 * x1 * x1 * x1 * x1 * x1 - 2 * x1 * x1 * x1 * x1 + 15 * x1 * x1 - 24 * x1 + 18;
- /*if ( wynik1 >= wynik2)
- {
- suma += (n * wynik2) + ((wynik1 - wynik2) * n / 2);
- }
- else
- {
- suma += (n * wynik1) + ((wynik2 - wynik1) * n / 2);
- }*/
- suma += (wynik1 + wynik2) * n / 2;
- }
- return suma;
- }
- int main(int argc, char *argv[])
- {
- float n;
- int k;
- float rangeAdd;
- float x1, x2;
- float wynik = 0;
- float readValue;
- n = atof(argv[1]);
- k = atoi(argv[2]);
- printf("n = %f\n", n);
- printf("k = %d\n", k);
- rangeAdd = 30 / k;
- int pipeTable[2];
- pid_t processID;
- pipe(pipeTable);
- x1 = -15;
- int i;
- for (i = 0; i < k; ++i)
- {
- if (i != 0)
- {
- x1 += rangeAdd;
- }
- x2 = x1 + rangeAdd - n;
- processID = fork();
- if (processID == 0)
- {
- wynik = calka(x1, x2, n);
- write(pipeTable[1], &wynik, sizeof(wynik));
- exit(0);
- }
- }
- for (i = 0; i < k; ++i)
- {
- read(pipeTable[0], &readValue, sizeof(readValue));
- wynik += readValue;
- }
- printf("wynik = %f\n", wynik);
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement