Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- double calka(double p, double k, int d, double (*f) (double)){
- double i=(k-p)/n;
- double s=0;
- while(p<k){
- s=s+0.5*i*(f(p+i)+f(p));
- p=p+i;
- }
- return s;
- }
- int main( int argc, char **argv ) {
- double a= argc > 1 ? atof( argv[1] ) : 0; /* pocz. przedzialu calkowania */
- double b= argc > 2 ? atof( argv[2] ) : M_PI; /* koniec przedzialu calkowania, M_PI jest zdef. w math.h */
- int n= argc > 3 ? atoi( argv[3] ) : 1000; /* liczba krokow calkowania */
- double f(double *x)= argc > 4 ? atof( argv[4] ) : f(x*x) /* funkcja calkowana */
- double s; calka(a,b,n,f(*x));
- printf("wynik calki: ");
- printf("%g", s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement