Czy mógł by ktoś mi wyjaśnić co jest źle i dlaczego ?
Kod: Zaznacz cały
1. #include<stdio.h>
2. #include<math.h>
3.
4. //typedef enum {false=0, true=1} bool;//
5.
6. double sumaszer(double x, double eps, int M, int *licz, bool *dokladnosc);
7. double Newton(double r, int n);
8.
9.
10. int main(void)
11. {
12. double a,b,dx,eps,wart_szer,wart_dokl;
13. int M,licznik;
14. bool dokl;
15. printf("Podaj liczby a, b, dx, eps, M:\n");
16. scanf("%lf %lf %lf %lf %d",&a,&b,&dx,&eps,&M);
17.
18. double x;
19.
20. for(x=a;x<=b;x+=dx)
21. {
22. wart_szer=sumaszer(x,eps,M,&licznik,&dokl);
23. wart_dokl=pow(1+x,1.0/3.0);
24.
25.
26. printf("%3lf %3lf %3lf %3d %3d\n\n\n",x,wart_szer,wart_dokl,licznik+1,dokl);
27. }
28.
29. return 0;
30. }
31.
32.
33. double Newton(double r, int n)
34. {
35. if(n>1)
36. return (r-n+1)/n*Newton(r,n-1);
37. else
38. return r;
39.
40. }
41.
42. double sumaszer(double x, double eps, int M, int *licz, bool *dokladnosc)
43. {
44. double suma=0;
45. double wyrazy[M+1]; //jak sprawdzam w Visual Studio to podkreśla mi tutaj M -że jest bład, ale nie wiem dlaczego//
46.
47. int i=0;
48. for(i=0;i<=M;i++)
49. {
50. if(i==0)
51. wyrazy[i]=1;
52. else
53. {
54. wyrazy[i]=Newton(1.0/3.0, i)*x;
55. }
56.
57. if(wyrazy[i]<eps)
58. {
59. break;
60. }else
61. {
62. suma+=wyrazy[i];
63. *licz=i;
64. }
65. }
66. if(i==M)
67. *dokladnosc=false;
68. else
69. *dokladnosc=true;
70.
71. return suma;
72. }