Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4.  
  5.  
  6. double func(double x);
  7. double calka(double a, double b, int N);
  8.  
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. int a, N;
  13.  
  14. a=0;
  15. double b = M_PI;
  16.  
  17. printf("POdaj dokladnosc N ");
  18. scanf("%d", &N);
  19.  
  20. printf("\n Calka wynosi: %.151f \n", calka(a,b,N));
  21. }
  22.  
  23. double calka(double a, double b, int N){
  24.  
  25. double suma = 0.0;
  26. double i, x1 = a, x2;
  27. double dx = (b-a)/N;
  28. double f1, f2, temp;
  29. double c = 0.5 * dx;
  30. temp = func(x1);
  31.  
  32. for(i =0; i<N;i++){
  33. x2 = x1+dx;
  34. f1 = temp;
  35. temp = f2 = func(x2);
  36. suma += c*(f1 + f2);
  37.  
  38. x1=x2;
  39. }
  40. return suma;
  41. }
  42.  
  43.  
  44. double func(double x){
  45. double sinus = sin(x);
  46. return sinus;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement