fork download
  1. #include <stdio.h>
  2.  
  3. typedef unsigned int Uint;
  4. #define N 100
  5. #define DP 15
  6. //RADIX == 10^LOG
  7. #define LOG 1
  8. #define RADIX 10
  9. typedef Uint Liczba[N+1];
  10.  
  11. void pisz( Liczba a ){ Uint i;
  12. for( i=1; i<=DP && !a[i]; i++ ) printf("%*s", LOG,"");
  13. printf("%*u", LOG, a[i]);
  14. for( i++; i<=DP; i++ ) printf("%0*u", LOG, a[i]);
  15. putchar('.');
  16. for( ; i<=N; i++ ) printf("%0*u", LOG, a[i]); }
  17.  
  18. void plus( Liczba a, Liczba b){ // a[]:=a[]+b[]
  19. for( Uint c=0, i=N; i>0; i-- ){
  20. c += a[i]+b[i];
  21. a[i] = c % RADIX;
  22. c /= RADIX;}}
  23.  
  24. void minus( Liczba a, Liczba b ) { // a[]:=a[]-b[]
  25. for( Uint c=0, i=N; i>0; i-- ){
  26. c += b[i];
  27. if( a[i]<c ){
  28. a[i] = RADIX + a[i] - c; c=1; }
  29. else {
  30. a[i] -= c; c=0; }}}
  31.  
  32. void razyU( Liczba a, Uint b ) { // a[]:=a[] * b
  33. for( Uint c=0,i=N; i>0; i-- ){
  34. c += a[i]*b;
  35. a[i]= c % RADIX;
  36. c /= RADIX; }}
  37.  
  38. int podzielU( Liczba w, Liczba a, Uint b ) { // w[]:=a[] / b
  39. Uint z=0; // return w[] != 0
  40. for( Uint c=0, i=1; i<=N; i++ ) {
  41. c = c*RADIX+a[i];
  42. w[i]= c/b % RADIX; if( w[i] ) z=1;
  43. c = c - w[i]*b;}
  44. return z;}
  45.  
  46. void wstawU( Liczba a, Uint b ) { // a[]:= b
  47. Uint i;
  48. for( i=0; i<=N; i++ ) a[i]=0;
  49. i=DP;
  50. while( b ) {
  51. a[i--] = b%RADIX; b /= RADIX; }}
  52.  
  53. void atg( Liczba a, Uint x ) { // a[]:= atan( 1/x )
  54. Liczba px;
  55. wstawU( px, 1 ); podzielU( px, px, x );
  56. wstawU( a, 0 ); plusU ( a, px );
  57. for( Uint n=1; ; n++){
  58. Liczba b;
  59. podzielU( w, w, x*x );
  60. if( ! podzielU( b, w, 2*n + 1 ) )
  61. break;
  62. if( n & 1 ) plus( a, b );
  63. else minus( a, b );}}
  64.  
  65. int main(void) {
  66. Liczba a;
  67. atg( a, 5 );pisz(a); puts("");
  68. printf("\n%0.14f\n", atan(1/5.0 ));
  69. return 0;
  70. }
  71.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
cc1: warnings being treated as errors
prog.c: In function ‘atg’:
prog.c:56: error: implicit declaration of function ‘plusU’
prog.c:59: error: ‘w’ undeclared (first use in this function)
prog.c:59: error: (Each undeclared identifier is reported only once
prog.c:59: error: for each function it appears in.)
prog.c: In function ‘main’:
prog.c:68: error: implicit declaration of function ‘atan’
prog.c:68: error: incompatible implicit declaration of built-in function ‘atan’
stdout
Standard output is empty