Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. double calka(double p, double k, int d, double (*f) (double)){
  5. double i=(k-p)/n;
  6. double s=0;
  7. while(p<k){
  8. s=s+0.5*i*(f(p+i)+f(p));
  9. p=p+i;
  10. }
  11. return s;
  12. }
  13. int main( int argc, char **argv ) {
  14. double a= argc > 1 ? atof( argv[1] ) : 0; /* pocz. przedzialu calkowania */
  15. double b= argc > 2 ? atof( argv[2] ) : M_PI; /* koniec przedzialu calkowania, M_PI jest zdef. w math.h */
  16. int n= argc > 3 ? atoi( argv[3] ) : 1000; /* liczba krokow calkowania */
  17. double f(double *x)= argc > 4 ? atof( argv[4] ) : f(x*x) /* funkcja calkowana */
  18. double s; calka(a,b,n,f(*x));
  19. printf("wynik calki: ");
  20. printf("%g", s);
  21. return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement