Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- double func(double x);
- double calka(double a, double b, int N);
- int main(int argc, char *argv[])
- {
- int a, N;
- a=0;
- double b = M_PI;
- printf("POdaj dokladnosc N ");
- scanf("%d", &N);
- printf("\n Calka wynosi: %.151f \n", calka(a,b,N));
- }
- double calka(double a, double b, int N){
- double suma = 0.0;
- double i, x1 = a, x2;
- double dx = (b-a)/N;
- double f1, f2, temp;
- double c = 0.5 * dx;
- temp = func(x1);
- for(i =0; i<N;i++){
- x2 = x1+dx;
- f1 = temp;
- temp = f2 = func(x2);
- suma += c*(f1 + f2);
- x1=x2;
- }
- return suma;
- }
- double func(double x){
- double sinus = sin(x);
- return sinus;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement