fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef unsigned int Uint;
  5. #define N 7800
  6. Uint DP=1;
  7. //RADIX == 10^LOG
  8. #define LOG 1
  9. #define RADIX 10
  10. typedef Uint Liczba[N+1];
  11.  
  12. void pisz( Liczba a, int ctrl){ Uint i;
  13. for( i=1; i<DP && !a[i]; i++ ) printf("%*s", LOG,"");
  14. printf("%*u", LOG, a[i]);
  15. for( i++; i<=DP; i++ ) printf("%0*u", LOG, a[i]);
  16. putchar('.');
  17. for( ; i<=N; i++ ) printf("%0*u", LOG, a[i]);
  18. if( ctrl < 0 ) puts("");}
  19.  
  20. void plus( Liczba a, Liczba b){ // a[]:=a[]+b[]
  21. for( Uint c=0, i=N; i>0; i-- ){
  22. c += a[i]+b[i];
  23. a[i] = c % RADIX;
  24. c /= RADIX;}}
  25.  
  26. void minus( Liczba a, Liczba b ) { // a[]:=a[]-b[]
  27. for( Uint c=0, i=N; i>0; i-- ){
  28. c += b[i];
  29. if( a[i]<c ){
  30. a[i] = RADIX + a[i] - c; c=1; }
  31. else {
  32. a[i] -= c; c=0; }}}
  33.  
  34. void razyU( Liczba a, Uint b ) { // a[]:=a[] * b
  35. for( Uint c=0,i=N; i>0; i-- ){
  36. c += a[i]*b;
  37. a[i]= c % RADIX;
  38. c /= RADIX; }}
  39.  
  40. int podzielU( Liczba w, Liczba a, Uint b ) { // w[]:=a[] / b
  41. Uint z=0; // return w[] != 0
  42. for( Uint c=0, i=1; i<=N; i++ ) {
  43. c = c*RADIX+a[i];
  44. w[i]= c/b % RADIX; if( w[i] ) z=1;
  45. c = c - w[i]*b;}
  46. return z;}
  47.  
  48. void wstawU( Liczba a, Uint b ) { // a[]:= b
  49. Uint i;
  50. for( i=0; i<=N; i++ ) a[i]=0;
  51. i=DP;
  52. while( b ) {
  53. a[i--] = b%RADIX; b /= RADIX; }}
  54.  
  55. void atg( Liczba a, Uint x ) { // a[]:= atan( 1/x )
  56. Liczba px;
  57. wstawU( px, 1 ); podzielU( px, px, x );
  58. wstawU( a, 0 ); plus ( a, px );
  59. for( Uint n=1; ; n++)
  60. Liczba b;
  61. podzielU( px, px, x*x );
  62. if( ! podzielU( b, px, 2*n + 1 ) )
  63. {printf("%d %d %d\n", n, x*x, 2*n+1);
  64. break;
  65. }
  66. if( n & 1 ) minus( a, b );
  67. else plus( a, b );}}
  68.  
  69. void silnia( Liczba a, Uint n ){ // a[]:= n!
  70. wstawU( a, 1 );
  71. while( n>1 )
  72. razyU( a, n-- );}
  73.  
  74. int main(void) {
  75. Liczba a, b;
  76. DP=1;
  77. atg ( a, 18 );
  78. razyU( a, 12 );
  79. atg ( b, 57 );
  80. razyU( b, 8 );
  81. plus ( a, b );
  82. atg ( b,239 );
  83. razyU( b, 5 );
  84. minus( a, b );
  85. razyU( a, 4 );
  86. pisz ( a, -1 );
  87.  
  88. //DP=N;
  89. //silnia(a1, 57 );
  90. //pisz ( a1, -1 );
  91. return 0;
  92. }
  93.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘atg’:
prog.c:60: error: expected expression before ‘Liczba’
prog.c:62: error: ‘b’ undeclared (first use in this function)
prog.c:62: error: (Each undeclared identifier is reported only once
prog.c:62: error: for each function it appears in.)
prog.c:62: error: ‘n’ undeclared (first use in this function)
prog.c:64: error: break statement not within loop or switch
prog.c: At top level:
prog.c:67: error: expected identifier or ‘(’ before ‘}’ token
stdout
Standard output is empty